abg

Animated background for X11
git clone git://git.laack.co/abg.git
Log | Files | Refs | README | LICENSE

commit 99fcc069b556c7b416f26d136c80c0de706df8f9
parent 428e13d46f382d3d3ebf526ff21a7067e3cb79a2
Author: Andrew Laack <andrew@laack.co>
Date:   Wed, 16 Sep 2026 12:33:29 -0500

Started benchmarking

Diffstat:
MMakefile | 10++++++++--
Abenchmarking/rlib-prim.txt | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mconfig.mk | 9+++++++--
Msrc/main.cpp | 53++++++++++++++++++++++++++++++++++++++++++++++++-----
4 files changed, 122 insertions(+), 9 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,13 +1,19 @@ include config.mk # building actual program -build: + + +debug-build: + ${DCOMMAND_P} src/main.cpp ${DCOMMAND_S} -o abg.out + + +release-build: ${COMMAND_P} src/main.cpp ${COMMAND_S} -o abg.out man: mkdir -p ${MANPREFIX}/man1 sed "s/VERSION/${VERSION}/g" < abg.1 > ${DESTDIR}${MANPREFIX}/man1/abg.1 chmod 644 ${DESTDIR}${MANPREFIX}/man1/abg.1 -install: build man +install: release-build man cp abg.out /usr/local/bin/abg clean: rm *.out diff --git a/benchmarking/rlib-prim.txt b/benchmarking/rlib-prim.txt @@ -0,0 +1,59 @@ +render time us: 6640 +prim step us: 7 +render time us: 1946 +prim step us: 7 +render time us: 2985 +prim step us: 11 +render time us: 2229 +prim step us: 6 +render time us: 1882 +prim step us: 10 +render time us: 1970 +prim step us: 7 +render time us: 2082 +prim step us: 8 +render time us: 3345 +prim step us: 10 +render time us: 1873 +prim step us: 7 +render time us: 1868 +prim step us: 5 +render time us: 794 +prim step us: 8 +render time us: 2027 +prim step us: 10 +render time us: 2774 +prim step us: 9 +render time us: 1970 +prim step us: 7 +render time us: 2015 +prim step us: 12 +render time us: 1879 +prim step us: 7 +render time us: 1917 +prim step us: 9 +render time us: 2304 +prim step us: 16 +render time us: 1916 +prim step us: 10 +render time us: 1845 +prim step us: 10 +render time us: 3320 +prim step us: 11 +render time us: 1958 +prim step us: 12 +render time us: 3531 +prim step us: 15 +render time us: 2111 +prim step us: 12 +render time us: 1847 +prim step us: 10 +render time us: 1982 +prim step us: 11 +render time us: 1945 +prim step us: 11 +render time us: 2671 +prim step us: 10 +render time us: 2017 +prim step us: 14 +render time us: 1936 diff --git a/config.mk b/config.mk @@ -11,8 +11,8 @@ TLIBS = -lCatch2Main -lCatch2 ${LIBS} # compiler CC = g++ -CFLAGS = -Ofast -std=c++23 -Wpedantic -Wall -Werror -Wextra -Wno-deprecated-declarations -Os -CTFLAGS = -fsanitize=address,undefined -O0 -std=c++23 -Wpedantic -Wall -Werror -Wextra -Wno-deprecated-declarations -Os +CFLAGS = -Ofast -std=c++23 -Wpedantic -Wall -Werror -Wextra -Wno-deprecated-declarations +CTFLAGS = -fsanitize=address,undefined -O0 -std=c++23 -Wpedantic -Wall -Werror -Wextra -Wno-deprecated-declarations BASE_FILES = src/prim.cpp src/graph.cpp src/edge.cpp src/utils.cpp src/vertex.cpp src/background.cpp @@ -21,3 +21,8 @@ COMMAND_S = ${BASE_FILES} ${LIBS} TCOMMAND_P = ${CC} ${CTFLAGS} TCOMMAND_S = ${BASE_FILES} ${TLIBS} + +# probably a good idea for debug mode to build the same as release, even though this loses out on asan and such. +# that's what tests are for. +DCOMMAND_P = ${CC} ${CFLAGS} -D NDEBUG +DCOMMAND_S = ${BASE_FILES} ${LIBS} diff --git a/src/main.cpp b/src/main.cpp @@ -7,6 +7,7 @@ #include <iostream> #include <queue> #include <unordered_set> +#include <chrono> #include "../include/background.hpp" #include "../include/constants.hpp" @@ -14,6 +15,14 @@ #include "../include/prim.hpp" #include "../vendor/argparse.hpp" + #ifdef NDEBUG + #define DLOG(statement) std::cout << statement << std::endl + #define DEBUG true + #else + #define DLOG(statement) + #define DEBUG false + #endif + int main(int argc, char** argv) { srand(clock()); @@ -83,6 +92,8 @@ int main(int argc, char** argv) { // with Font. InitWindow(xMax, yMax, "abg"); + + sendToBg("abg"); while (!WindowShouldClose()) { @@ -98,12 +109,44 @@ int main(int argc, char** argv) { visitedIndices.insert(0); while (!WindowShouldClose() && toVisit.size() != 0) { - BeginDrawing(); - ClearBackground(BLACK); - g.render(); - EndDrawing(); + if(DEBUG) { + auto start = std::chrono::system_clock::now(); + BeginDrawing(); + ClearBackground(BLACK); + g.render(); + EndDrawing(); + auto end = std::chrono::system_clock::now(); + auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end - start); + std::cout << "render time us: "<< elapsed.count() << std::endl; + } else { + BeginDrawing(); + ClearBackground(BLACK); + g.render(); + EndDrawing(); + } + + // since we wait sleepTime here, the bg render has a render delta of + // at minimum sleepTime when switching tags in dwm, this is rather + // annoying because the screen doesn't repaint until the sleep time + // passes, which results in artifacts on screen. + + // despite this, calling render a lot of times is rather intensive + // (at least on my hardware) and so this tradeoff is accepted for + // now, unless there's a simple approach that allows for preemption + + usleep((int)(sleepTime * 1000000)); - oneStepPrim(toVisit, visitedIndices, g); + + if(DEBUG) { + auto start = std::chrono::system_clock::now(); + oneStepPrim(toVisit, visitedIndices, g); + auto end = std::chrono::system_clock::now(); + auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end - start); + std::cout << "prim step us: "<< elapsed.count() << std::endl; + } else { + oneStepPrim(toVisit, visitedIndices, g); + } + } } }