diff --git a/Makefile b/Makefile index ae2f996..8744b71 100644 --- a/Makefile +++ b/Makefile @@ -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')" diff --git a/benchmarks/loop-c b/benchmarks/loop-c new file mode 100755 index 0000000..1d9bee5 Binary files /dev/null and b/benchmarks/loop-c differ diff --git a/benchmarks/loop.fzs b/benchmarks/loop.fzs index 9a76b7a..78c03e2 100644 --- a/benchmarks/loop.fzs +++ b/benchmarks/loop.fzs @@ -3,6 +3,7 @@ uint i = 0; uint sum = 0; for (i = 0; i < 1000000; i = i + 1) -{ sum = sum + i; -} + +printline(sum); + diff --git a/benchmarks/loop.py b/benchmarks/loop.py new file mode 100644 index 0000000..be130e9 --- /dev/null +++ b/benchmarks/loop.py @@ -0,0 +1,4 @@ +s = 0 +for i in range(1_000_000): + s += i +print(s)