mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Benchmarks are working, but empty
Lots of work and stress for a tint bit of progress. See #131
This commit is contained in:
24
.github/workflows/benchmarks.yml
vendored
Normal file
24
.github/workflows/benchmarks.yml
vendored
Normal file
@@ -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 }}
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -41,6 +41,7 @@
|
|||||||
*.su
|
*.su
|
||||||
*.idb
|
*.idb
|
||||||
*.pdb
|
*.pdb
|
||||||
|
*.log
|
||||||
|
|
||||||
# Kernel Module Compile Results
|
# Kernel Module Compile Results
|
||||||
*.mod*
|
*.mod*
|
||||||
|
|||||||
@@ -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)
|
#define TOY_ARRAY_ALLOCATE() Toy_resizeArray(NULL, TOY_ARRAY_INITIAL_CAPACITY)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//quick free
|
||||||
|
#ifndef TOY_ARRAY_FREE
|
||||||
|
#define TOY_ARRAY_FREE(array) Toy_resizeArray(array, 0)
|
||||||
|
#endif
|
||||||
|
|
||||||
//one line to expand the array
|
//one line to expand the array
|
||||||
#ifndef TOY_ARRAY_EXPAND
|
#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))
|
#define TOY_ARRAY_EXPAND(array) (array = (array != NULL && (array)->count + 1 > (array)->capacity ? Toy_resizeArray(array, (array)-> capacity * TOY_ARRAY_EXPANSION_RATE) : array))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//quick push back
|
||||||
|
#ifndef TOY_ARRAY_PUSHBACK
|
||||||
|
#define TOY_ARRAY_PUSHBACK(array, value) (TOY_ARRAY_EXPAND(array),(array)->data[(array)->count++] = (value))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|||||||
26
tests/benchmarks/array.c
Normal file
26
tests/benchmarks/array.c
Normal 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;
|
||||||
|
}
|
||||||
3
tests/benchmarks/gdb_init
Normal file
3
tests/benchmarks/gdb_init
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
set breakpoint pending on
|
||||||
|
|
||||||
|
|
||||||
94
tests/benchmarks/makefile
Normal file
94
tests/benchmarks/makefile
Normal 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)
|
||||||
|
|
||||||
@@ -35,7 +35,6 @@ build: $(TEST_OBJDIR)$(TEST_SRCFILES:.c=.o)
|
|||||||
$(TEST_OBJDIR)%.o: $(TEST_SRCDIR)%.c
|
$(TEST_OBJDIR)%.o: $(TEST_SRCDIR)%.c
|
||||||
$(CC) -c -o $@ $< $(CFLAGS) -fdata-sections -ffunction-sections
|
$(CC) -c -o $@ $< $(CFLAGS) -fdata-sections -ffunction-sections
|
||||||
|
|
||||||
|
|
||||||
.PRECIOUS: $(TEST_OUTDIR)%.exe
|
.PRECIOUS: $(TEST_OUTDIR)%.exe
|
||||||
$(TEST_OUTDIR)%.exe: $(TEST_OBJDIR)%.o
|
$(TEST_OUTDIR)%.exe: $(TEST_OBJDIR)%.o
|
||||||
$(CC) -o $@ $< $(CFLAGS) $(LIBS) $(LDFLAGS)
|
$(CC) -o $@ $< $(CFLAGS) $(LIBS) $(LDFLAGS)
|
||||||
|
|||||||
Reference in New Issue
Block a user