Benchmarks are working, but empty

Lots of work and stress for a tint bit of progress.

See #131
This commit is contained in:
2024-10-19 15:57:07 +11:00
parent 787a1cca84
commit 5d37d06343
10 changed files with 159 additions and 1 deletions

26
tests/benchmarks/array.c Normal file
View File

@@ -0,0 +1,26 @@
#include "toy_array.h"
#include <stdio.h>
#include <stdlib.h>
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;
}

View File

@@ -0,0 +1,3 @@
set breakpoint pending on

94
tests/benchmarks/makefile Normal file
View File

@@ -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)