diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml new file mode 100644 index 0000000..30979d2 --- /dev/null +++ b/.github/workflows/benchmarks.yml @@ -0,0 +1,24 @@ +name: Benchmarks + +#trigger when these occur +on: + workflow_dispatch: + +#Benchmarks are currently only supported on one platform +jobs: + run-test-cases: + continue-on-error: true + strategy: + matrix: + platforms: + - { os: ubuntu-latest, preinstall: sudo apt-get install time } + commands: + - { exec: make -C tests/benchmarks -k } + + runs-on: ${{ matrix.platforms.os }} + steps: + - uses: actions/checkout@v4 + - name: Preinstall dependencies + run: ${{ matrix.platforms.preinstall }} + - name: run the tests + run: ${{ matrix.commands.exec }} diff --git a/.gitignore b/.gitignore index c6127b3..4bdbcec 100644 --- a/.gitignore +++ b/.gitignore @@ -41,6 +41,7 @@ *.su *.idb *.pdb +*.log # Kernel Module Compile Results *.mod* diff --git a/source/toy_array.h b/source/toy_array.h index 9c1d370..0971964 100644 --- a/source/toy_array.h +++ b/source/toy_array.h @@ -26,7 +26,18 @@ TOY_API Toy_Array* Toy_resizeArray(Toy_Array* array, unsigned int capacity); #define TOY_ARRAY_ALLOCATE() Toy_resizeArray(NULL, TOY_ARRAY_INITIAL_CAPACITY) #endif +//quick free +#ifndef TOY_ARRAY_FREE +#define TOY_ARRAY_FREE(array) Toy_resizeArray(array, 0) +#endif + //one line to expand the array #ifndef TOY_ARRAY_EXPAND #define TOY_ARRAY_EXPAND(array) (array = (array != NULL && (array)->count + 1 > (array)->capacity ? Toy_resizeArray(array, (array)-> capacity * TOY_ARRAY_EXPANSION_RATE) : array)) #endif + +//quick push back +#ifndef TOY_ARRAY_PUSHBACK +#define TOY_ARRAY_PUSHBACK(array, value) (TOY_ARRAY_EXPAND(array),(array)->data[(array)->count++] = (value)) +#endif + diff --git a/tests/benchmarks/JavaScript/.gitkeep b/tests/benchmarks/JavaScript/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/tests/benchmarks/Toy/.gitkeep b/tests/benchmarks/Toy/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/tests/benchmarks/array.c b/tests/benchmarks/array.c new file mode 100644 index 0000000..b9a0207 --- /dev/null +++ b/tests/benchmarks/array.c @@ -0,0 +1,26 @@ +#include "toy_array.h" + +#include +#include + +int main(int argc, char* argv[]) { +// for (int i = 0; i < argc; i++) { +// printf("argv[%d]: %s\n", i, argv[i]); +// } + +// if (iargc != 2) return -1; + + unsigned int iterations = atoi(argv[1]); + +// printf("Found %d iterations\n", iterations); + + Toy_Array* array = TOY_ARRAY_ALLOCATE(); + + for (int i = 0; i < iterations; i++) { + TOY_ARRAY_PUSHBACK(array, TOY_VALUE_FROM_INTEGER(i)); + } + + TOY_ARRAY_FREE(array); + + return 0; +} diff --git a/tests/benchmarks/gdb_init b/tests/benchmarks/gdb_init new file mode 100644 index 0000000..31f1f7b --- /dev/null +++ b/tests/benchmarks/gdb_init @@ -0,0 +1,3 @@ +set breakpoint pending on + + diff --git a/tests/benchmarks/lua/.gitkeep b/tests/benchmarks/lua/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/tests/benchmarks/makefile b/tests/benchmarks/makefile new file mode 100644 index 0000000..5a46574 --- /dev/null +++ b/tests/benchmarks/makefile @@ -0,0 +1,94 @@ +#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 + +#patch in these for compatability +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)/*.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 + +.PHONY: build-source +build-source: $(TEST_OUTDIR) $(TEST_OBJDIR) $(addprefix $(TEST_OBJDIR)/,$(notdir $(TEST_SOURCEFILES:.c=.o))) + +$(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 + +.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 + +.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) + +#util targets +$(TEST_OUTDIR): + mkdir $(TEST_OUTDIR) + +$(TEST_OBJDIR): + mkdir $(TEST_OBJDIR) + diff --git a/tests/standalone/makefile b/tests/standalone/makefile index 9ede8a2..f7d9d38 100644 --- a/tests/standalone/makefile +++ b/tests/standalone/makefile @@ -35,7 +35,6 @@ build: $(TEST_OBJDIR)$(TEST_SRCFILES:.c=.o) $(TEST_OBJDIR)%.o: $(TEST_SRCDIR)%.c $(CC) -c -o $@ $< $(CFLAGS) -fdata-sections -ffunction-sections - .PRECIOUS: $(TEST_OUTDIR)%.exe $(TEST_OUTDIR)%.exe: $(TEST_OBJDIR)%.o $(CC) -o $@ $< $(CFLAGS) $(LIBS) $(LDFLAGS)