From 9865d62e52afce14d63b3a9ddc3dd8266de92bde Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Tue, 2 Jul 2024 16:02:44 +0300 Subject: [PATCH 1/3] docs: Fixup compile commands so the actually generate expected binary names --- readme.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/readme.md b/readme.md index 007b01c..f697f9c 100644 --- a/readme.md +++ b/readme.md @@ -37,7 +37,7 @@ cccccccc;.:odl:.;cccccccccccccc:,. CPU: 11th Gen Intel i5-11400H (12) @ 4. Now, these are the results: ``` -$ clang++ -stdlib=libstdc++ -O3 c++.cpp +$ clang++ -stdlib=libstdc++ -O3 c++.cpp -o c++ $ time ./c++ The result is 9999999999 real 1m59.314s @@ -55,8 +55,8 @@ sys 0m0.002s ``` ``` -$ zig build-exe zig.zig -target x86_64-linux -O ReleaseSafe -$ time ./zig +$ zig build-exe zig.zig -target x86_64-linux -O ReleaseSafe --name zig-safe +$ time ./zig-safe The result is 9999999999 real 1m38.193s @@ -65,8 +65,8 @@ sys 0m0.003s ``` ``` -$ zig build-exe zig.zig -target x86_64-linux -O ReleaseFast -$ time ./zig +$ zig build-exe zig.zig -target x86_64-linux -O ReleaseFast --name zig-fast +$ time ./zig-fast The result is 9999999999 real 1m56.232s @@ -75,7 +75,7 @@ sys 0m0.003s ``` ``` -$ clang -stdlib=libgcc -O3 c.c +$ clang -stdlib=libgcc -O3 c.c -o c $ time ./c The result is 9999999999 real 1m58.715s From 24b2c529136722281f09e9d31ec4402a1d6c822b Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Tue, 2 Jul 2024 15:46:48 +0300 Subject: [PATCH 2/3] Add Makefile that can build the various targets --- Makefile | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..86a3f8a --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +.PHONY: all +all: c++ rust zig-safe zig-fast c + +c: c.c + clang -stdlib=libgcc -O3 $< -o $@ + +c++: c++.cpp + clang++ -stdlib=libstdc++ -O3 $< -o $@ + +rust: rust.rs + rustc -C opt-level=3 $< + +zig-safe: zig.zig + zig build-exe $< -target x86_64-linux -O ReleaseSafe --name $@ + +zig-fast: zig.zig + zig build-exe $< -target x86_64-linux -O ReleaseFast --name $@ From debeb2dd305512fa5c08eddc741f751298953448 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Tue, 2 Jul 2024 15:53:03 +0300 Subject: [PATCH 3/3] Add benchmark target using hyperfine --- Makefile | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 86a3f8a..7448584 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,12 @@ +TARGETS = c++ rust zig-safe zig-fast c +RUNS ?= 3 + .PHONY: all -all: c++ rust zig-safe zig-fast c +all: $(TARGETS) + +.PHONY: benchmark +benchmark: all + hyperfine -r$(RUNS) $(foreach TARGET,$(TARGETS),./$(TARGET)) c: c.c clang -stdlib=libgcc -O3 $< -o $@