diff --git a/source/toy_table.h b/source/toy_table.h index 3f91f07..b92dc58 100644 --- a/source/toy_table.h +++ b/source/toy_table.h @@ -33,6 +33,7 @@ TOY_API Toy_Table* Toy_private_adjustTableCapacity(Toy_Table* oldTable, unsigned #define TOY_TABLE_INITIAL_CAPACITY 8 #endif +//NOTE: The DOOM hack needs a power of 2 #ifndef TOY_TABLE_EXPANSION_RATE #define TOY_TABLE_EXPANSION_RATE 2 #endif diff --git a/tests/benchmarks/modulo_hack/bench_main.c b/tests/benchmarks/bench_main.c similarity index 100% rename from tests/benchmarks/modulo_hack/bench_main.c rename to tests/benchmarks/bench_main.c diff --git a/tests/benchmarks/gdb_init b/tests/benchmarks/gdb_init deleted file mode 100644 index 6c33498..0000000 --- a/tests/benchmarks/gdb_init +++ /dev/null @@ -1,2 +0,0 @@ -set breakpoint pending on - diff --git a/tests/benchmarks/makefile b/tests/benchmarks/makefile index 5a46574..0b20cd7 100644 --- a/tests/benchmarks/makefile +++ b/tests/benchmarks/makefile @@ -14,7 +14,7 @@ else @echo "LDFLAGS set failed - what platform is this?" endif -#patch in these for compatability +#patched in TOY_SOURCEDIR=source #directories @@ -27,63 +27,53 @@ TEST_OBJDIR=obj #file names TEST_SOURCEFILES=$(wildcard $(TEST_SOURCEDIR)/*.c) -TEST_CASESFILES=$(wildcard $(TEST_CASESDIR)/*.c) - -#utils -UC=$(shell echo '$1' | tr '[:lower:]' '[:upper:]') - -#kick off -all: $(TEST_OBJDIR) $(TEST_OUTDIR) build-files run-all - -run-all: - for exe in $(wildcard $(TEST_OUTDIR)/*.exe) ; do \ - i=1 ; \ - exp=10 ; \ - while [ $$i -le 8 ] ; do \ - /usr/bin/time --format "%C: %U %W" $$exe $$exp ; \ - exp=$$((exp * 10)); \ - i=$$(( i + 1 )) ; \ - done ; \ - done - - -# gdb $$exe -ix gdb_init -ex=run -ex=bt --batch --return-child-result --args "$$exe" $$exp ; \ - -#build the source files -build-files: - for src in $(TEST_CASESFILES) ; do \ - $(MAKE) SRC=$$src build-parameters ; \ - done - -build-parameters: - initial=8 ; \ - while [ $$initial -le 256 ] ; do \ - expansion=2 ; \ - while [ $$expansion -le 8 ] ; do \ - $(MAKE) INITIAL=$$initial EXPANSION=$$expansion build-executable ; \ - expansion=$$((expansion + 1)) ; \ - done ; \ - initial=$$((initial + initial)) ; \ - done - -build-executable: - $(MAKE) UCSRC=$(call UC,$(basename $(notdir $(SRC)))) build-source - $(MAKE) UCSRC=$(call UC,$(basename $(notdir $(SRC)))) build-src - $(MAKE) UCSRC=$(call UC,$(basename $(notdir $(SRC)))) build-exe - +TEST_CASESFILES=$(wildcard $(TEST_CASESDIR)/bench_*.c) + +#build the object files, compile the test cases, and run +all: clean + $(MAKE) build-source + $(MAKE) build-cases + $(MAKE) build-link + $(MAKE) build-run + +all-override: clean + $(MAKE) TEST_SOURCEFILES='$(subst $(TEST_SOURCEDIR)/$(OVERRIDE),$(OVERRIDE),$(TEST_SOURCEFILES))' build-source-override + $(MAKE) build-cases + $(MAKE) build-link + $(MAKE) build-run + +.PHONY: build-source-override +build-source-override: $(TEST_OUTDIR) $(TEST_OBJDIR) $(addprefix $(TEST_OBJDIR)/,$(notdir $(TEST_SOURCEFILES:.c=.o))) + $(CC) -c -o $(TEST_OBJDIR)/$(OVERRIDE:.c=.o) $(OVERRIDE) $(addprefix -I,$(TEST_SOURCEDIR)) $(CFLAGS) -fdata-sections -ffunction-sections + +#targets for each step .PHONY: build-source build-source: $(TEST_OUTDIR) $(TEST_OBJDIR) $(addprefix $(TEST_OBJDIR)/,$(notdir $(TEST_SOURCEFILES:.c=.o))) +.PHONY: build-cases +build-cases: $(TEST_OUTDIR) $(TEST_OBJDIR) $(addprefix $(TEST_OBJDIR)/,$(notdir $(TEST_CASESFILES:.c=.o))) + +.PHONY: build-link +build-link: $(TEST_OUTDIR) $(TEST_OBJDIR) $(addprefix $(TEST_OUTDIR)/,$(notdir $(TEST_CASESFILES:%.c=%.exe))) + +.PHONY: build-run +build-run: $(addprefix $(TEST_OUTDIR)/,$(notdir $(TEST_CASESFILES:%.c=%.exe))) $(addprefix $(TEST_OUTDIR)/,$(notdir $(TEST_CASESFILES:%.c=%.run))) + +#compilation steps $(TEST_OBJDIR)/%.o: $(TEST_SOURCEDIR)/%.c - $(CC) -DTOY_$(UCSRC)_INITIAL_CAPACITY=$(INITIAL) -DTOY_$(UCSRC)_EXPANSION_RATE=$(EXPANSION) -c -o $@ $< $(addprefix -I,$(TEST_SOURCEDIR)) $(CFLAGS) -fdata-sections -ffunction-sections + $(CC) -c -o $@ $< $(addprefix -I,$(TEST_SOURCEDIR)) $(CFLAGS) -fdata-sections -ffunction-sections + +$(TEST_OBJDIR)/%.o: $(TEST_CASESDIR)/%.c + $(CC) -c -o $@ $< $(addprefix -I,$(TEST_SOURCEDIR) $(TEST_CASESDIR)) $(CFLAGS) -fdata-sections -ffunction-sections -.PHONY: build-src -build-src: - $(CC) -DTOY_$(UCSRC)_INITIAL_CAPACITY=$(INITIAL) -DTOY_$(UCSRC)_EXPANSION_RATE=$(EXPANSION) -c -o $(TEST_OBJDIR)/$(SRC:.c=.o) $(SRC) $(addprefix -I,$(TEST_SOURCEDIR)) $(CFLAGS) -fdata-sections -ffunction-sections +$(TEST_OUTDIR)/%.exe: $(TEST_OBJDIR)/%.o + @$(CC) -o $@ $< $(addprefix $(TEST_OBJDIR)/,$(notdir $(TEST_SOURCEFILES:.c=.o))) $(CFLAGS) $(LIBS) $(LDFLAGS) -.PHONY: build-exe -build-exe: - $(CC) -o $(TEST_OUTDIR)/$(SRC:.c=)-$(INITIAL)-$(EXPANSION).exe $(TEST_OBJDIR)/$(SRC:.c=.o) $(addprefix $(TEST_OBJDIR)/,$(notdir $(TEST_SOURCEFILES:.c=.o))) $(CFLAGS) $(LIBS) $(LDFLAGS) +.PRECIOUS: $(TEST_OUTDIR)/%.run +$(TEST_OUTDIR)/%.run: $(TEST_OUTDIR)/%.exe + @/usr/bin/time --format "%C; $(OVERRIDE)\nUser System\n%U %E" $< 100000000 512 + @/usr/bin/time --format "%C; $(OVERRIDE)\nUser System\n%U %E" $< 100000000 1024 + @/usr/bin/time --format "%C; $(OVERRIDE)\nUser System\n%U %E" $< 100000000 4096 #util targets $(TEST_OUTDIR): @@ -92,3 +82,34 @@ $(TEST_OUTDIR): $(TEST_OBJDIR): mkdir $(TEST_OBJDIR) +#util commands +.PHONY: clean +clean: +ifeq ($(shell uname),Linux) + find . -type f -name '*.o' -delete + find . -type f -name '*.a' -delete + find . -type f -name '*.exe' -delete + find . -type f -name '*.dll' -delete + find . -type f -name '*.lib' -delete + find . -type f -name '*.so' -delete + find . -type f -name '*.dylib' -delete + find . -type d -name 'out' -delete + find . -type d -name 'obj' -delete +else ifeq ($(OS),Windows_NT) + $(RM) *.o *.a *.exe *.dll *.lib *.so *.dylib + $(RM) out + $(RM) obj +else ifeq ($(shell uname),Darwin) + find . -type f -name '*.o' -delete + find . -type f -name '*.a' -delete + find . -type f -name '*.exe' -delete + find . -type f -name '*.dll' -delete + find . -type f -name '*.lib' -delete + find . -type f -name '*.so' -delete + find . -type f -name '*.dylib' -delete + find . -type d -name 'out' -delete + find . -type d -name 'obj' -delete +else + @echo "Deletion failed - what platform is this?" +endif + diff --git a/tests/benchmarks/modulo_hack/makefile b/tests/benchmarks/modulo_hack/makefile deleted file mode 100644 index 70fcd18..0000000 --- a/tests/benchmarks/modulo_hack/makefile +++ /dev/null @@ -1,115 +0,0 @@ -#compiler settings -CC=gcc -CFLAGS+=-std=c17 -g -Wall -Werror -Wno-unused-parameter -Wno-unused-function -Wno-unused-variable -Wformat=2 -LIBS+=-lm -LDFLAGS+= - -ifeq ($(shell uname),Linux) -LDFLAGS=-Wl,--gc-sections -else ifeq ($(OS),Windows_NT) -LDFLAGS=-Wl,--gc-sections -else ifeq ($(shell uname),Darwin) -LDFLAGS=-Wl,-dead_strip -else - @echo "LDFLAGS set failed - what platform is this?" -endif - -#patched in -TOY_SOURCEDIR=source - -#directories -TEST_ROOTDIR=../../.. -TEST_SOURCEDIR=$(TEST_ROOTDIR)/$(TOY_SOURCEDIR) -TEST_CASESDIR=. - -TEST_OUTDIR=out -TEST_OBJDIR=obj - -#file names -TEST_SOURCEFILES=$(wildcard $(TEST_SOURCEDIR)/*.c) -TEST_CASESFILES=$(wildcard $(TEST_CASESDIR)/bench_*.c) - -#build the object files, compile the test cases, and run -all: clean - $(MAKE) build-source - $(MAKE) build-cases - $(MAKE) build-link - $(MAKE) build-run - -all-override: clean - $(MAKE) TEST_SOURCEFILES='$(subst $(TEST_SOURCEDIR)/$(OVERRIDE),$(OVERRIDE),$(TEST_SOURCEFILES))' build-source-override - $(MAKE) build-cases - $(MAKE) build-link - $(MAKE) build-run - -.PHONY: build-source-override -build-source-override: $(TEST_OUTDIR) $(TEST_OBJDIR) $(addprefix $(TEST_OBJDIR)/,$(notdir $(TEST_SOURCEFILES:.c=.o))) - $(CC) -c -o $(TEST_OBJDIR)/$(OVERRIDE:.c=.o) $(OVERRIDE) $(addprefix -I,$(TEST_SOURCEDIR)) $(CFLAGS) -fdata-sections -ffunction-sections - -#targets for each step -.PHONY: build-source -build-source: $(TEST_OUTDIR) $(TEST_OBJDIR) $(addprefix $(TEST_OBJDIR)/,$(notdir $(TEST_SOURCEFILES:.c=.o))) - -.PHONY: build-cases -build-cases: $(TEST_OUTDIR) $(TEST_OBJDIR) $(addprefix $(TEST_OBJDIR)/,$(notdir $(TEST_CASESFILES:.c=.o))) - -.PHONY: build-link -build-link: $(TEST_OUTDIR) $(TEST_OBJDIR) $(addprefix $(TEST_OUTDIR)/,$(notdir $(TEST_CASESFILES:%.c=%.exe))) - -.PHONY: build-run -build-run: $(addprefix $(TEST_OUTDIR)/,$(notdir $(TEST_CASESFILES:%.c=%.exe))) $(addprefix $(TEST_OUTDIR)/,$(notdir $(TEST_CASESFILES:%.c=%.run))) - -#compilation steps -$(TEST_OBJDIR)/%.o: $(TEST_SOURCEDIR)/%.c - $(CC) -c -o $@ $< $(addprefix -I,$(TEST_SOURCEDIR)) $(CFLAGS) -fdata-sections -ffunction-sections - -$(TEST_OBJDIR)/%.o: $(TEST_CASESDIR)/%.c - $(CC) -c -o $@ $< $(addprefix -I,$(TEST_SOURCEDIR) $(TEST_CASESDIR)) $(CFLAGS) -fdata-sections -ffunction-sections - -$(TEST_OUTDIR)/%.exe: $(TEST_OBJDIR)/%.o - @$(CC) -o $@ $< $(addprefix $(TEST_OBJDIR)/,$(notdir $(TEST_SOURCEFILES:.c=.o))) $(CFLAGS) $(LIBS) $(LDFLAGS) - -.PRECIOUS: $(TEST_OUTDIR)/%.run -$(TEST_OUTDIR)/%.run: $(TEST_OUTDIR)/%.exe - @/usr/bin/time --format "%C; $(OVERRIDE)\nUser System\n%U %E" $< 100000000 512 - @/usr/bin/time --format "%C; $(OVERRIDE)\nUser System\n%U %E" $< 100000000 1024 - @/usr/bin/time --format "%C; $(OVERRIDE)\nUser System\n%U %E" $< 100000000 4096 - -#util targets -$(TEST_OUTDIR): - mkdir $(TEST_OUTDIR) - -$(TEST_OBJDIR): - mkdir $(TEST_OBJDIR) - -#util commands -.PHONY: clean -clean: -ifeq ($(shell uname),Linux) - find . -type f -name '*.o' -delete - find . -type f -name '*.a' -delete - find . -type f -name '*.exe' -delete - find . -type f -name '*.dll' -delete - find . -type f -name '*.lib' -delete - find . -type f -name '*.so' -delete - find . -type f -name '*.dylib' -delete - find . -type d -name 'out' -delete - find . -type d -name 'obj' -delete -else ifeq ($(OS),Windows_NT) - $(RM) *.o *.a *.exe *.dll *.lib *.so *.dylib - $(RM) out - $(RM) obj -else ifeq ($(shell uname),Darwin) - find . -type f -name '*.o' -delete - find . -type f -name '*.a' -delete - find . -type f -name '*.exe' -delete - find . -type f -name '*.dll' -delete - find . -type f -name '*.lib' -delete - find . -type f -name '*.so' -delete - find . -type f -name '*.dylib' -delete - find . -type d -name 'out' -delete - find . -type d -name 'obj' -delete -else - @echo "Deletion failed - what platform is this?" -endif -