feat: add runtime speed comparison between fz, c and cpython

This commit is contained in:
samsonium
2026-10-29 05:21:31 +03:00
parent 7b804b8809
commit dcab2a8875
4 changed files with 38 additions and 7 deletions
+31 -5
View File
@@ -5,13 +5,15 @@ RUNS ?= 7
WARMUP ?= 2
MAX_ITER ?= 2000000
current_time = python3 -c "import time; print(time.time())"
build:
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
cmake --build build
build-release:
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release $(COMPARING)
cmake --build build $(COMPARING)
debug-c: build
gdb --args ./build/fzc ${FILE}
@@ -22,8 +24,32 @@ debug-vm: build
test: build
ctest --output-on-failure --test-dir build
# Compile the benchmark once, then measure only VM process execution.
test-release: build-release
ctest --output-on-failure --test-dir build
bench: COMPARING=&>/dev/null
bench: build-release
./build/fzc -o build/benchmark.fzb $(BENCH_FILE)
python3 scripts/benchmark.py --runs $(RUNS) --warmup $(WARMUP) \
@./build/fzc -o build/benchmark.fzb $(BENCH_FILE)
@python3 scripts/benchmark.py --runs $(RUNS) --warmup $(WARMUP) \
--max-iter $(MAX_ITER) --vm ./build/fz --program build/benchmark.fzb
compare: COMPARING=&>/dev/null
compare: build-release
@echo "=== Million sums benchmark ==="
@./build/fzc -o build/bench.fzb $(BENCH_FILE) 1>/dev/null 2>/dev/null
@ST=$$($(current_time)); \
./build/fz --allow-infinite build/bench.fzb 1>/dev/null 2>/dev/null; \
ET=$$($(current_time)); \
python3 -c "delta = ($$ET - $$ST) * 1000; print(f'FZLang : {delta:.5f} ms')"
@ST=$$($(current_time)); \
./benchmarks/loop-c 1>/dev/null 2>/dev/null; \
ET=$$($(current_time)); \
python3 -c "delta = ($$ET - $$ST) * 1000; print(f'C : {delta:.5f} ms')"
@ST=$$($(current_time)); \
python3 ./benchmarks/loop.py 1>/dev/null 2>/dev/null; \
ET=$$($(current_time)); \
python3 -c "delta = ($$ET - $$ST) * 1000; print(f'CPython: {delta:.5f} ms')"
BIN
View File
Binary file not shown.
+3 -2
View File
@@ -3,6 +3,7 @@ uint i = 0;
uint sum = 0;
for (i = 0; i < 1000000; i = i + 1)
{
sum = sum + i;
}
printline(sum);
+4
View File
@@ -0,0 +1,4 @@
s = 0
for i in range(1_000_000):
s += i
print(s)