From 2db67702f07002fc0382d294269e0208dbd338ab Mon Sep 17 00:00:00 2001 From: Bill Morgan Date: Sun, 11 Apr 2021 19:13:57 -0500 Subject: [PATCH 1/5] fix nbodies warnings on Mac for benchmarks Nbodies/nbodies_c.c:4:9: warning: 'M_PI' macro redefined [-Wmacro-redefined] #define M_PI 3.14159265359 ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/math.h:692:9: note: previous definition is here #define M_PI 3.14159265358979323846264338327950288 /* pi */ ^ 1 warning generated. Nbodies/nbodies_cpp.cpp:4:9: warning: 'M_PI' macro redefined [-Wmacro-redefined] #define M_PI 3.14159265358979323846 ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/math.h:692:9: note: previous definition is here #define M_PI 3.14159265358979323846264338327950288 /* pi */ ^ 1 warning generated. --- benchmarks/Nbodies/nbodies_c.c | 1 + benchmarks/Nbodies/nbodies_cpp.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/benchmarks/Nbodies/nbodies_c.c b/benchmarks/Nbodies/nbodies_c.c index e46195d..e4c43e6 100644 --- a/benchmarks/Nbodies/nbodies_c.c +++ b/benchmarks/Nbodies/nbodies_c.c @@ -1,6 +1,7 @@ #include #include +#undef M_PI #define M_PI 3.14159265359 static const double solar_mass = 4 * M_PI * M_PI; diff --git a/benchmarks/Nbodies/nbodies_cpp.cpp b/benchmarks/Nbodies/nbodies_cpp.cpp index c8f0f13..dbfef0c 100644 --- a/benchmarks/Nbodies/nbodies_cpp.cpp +++ b/benchmarks/Nbodies/nbodies_cpp.cpp @@ -1,6 +1,7 @@ #include #include +#undef M_PI #define M_PI 3.14159265358979323846 static const double solar_mass = 4 * M_PI * M_PI; From 76ad03d5488db4e31a375e274db8276ccc107710 Mon Sep 17 00:00:00 2001 From: Bill Morgan Date: Sun, 11 Apr 2021 20:01:24 -0500 Subject: [PATCH 2/5] fix warning GC/gc_cello.c:40:1: warning: non-void function does not return a value [-Wreturn-type] } ^ 1 warning generated. --- benchmarks/GC/gc_cello.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/GC/gc_cello.c b/benchmarks/GC/gc_cello.c index 9891ac6..48cea79 100644 --- a/benchmarks/GC/gc_cello.c +++ b/benchmarks/GC/gc_cello.c @@ -36,5 +36,5 @@ int main(int argc, char** argv) { for (size_t i = 0; i < 100; i++) { create_objects(0); } - + return 0; } From 3354cc3bd301fd2e6f40b18601841c68aa89dda5 Mon Sep 17 00:00:00 2001 From: Bill Morgan Date: Sun, 11 Apr 2021 20:26:31 -0500 Subject: [PATCH 3/5] ignore benchmark programs --- .gitignore | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index e59c604..9e7695d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ # Main -*.log +*.log *~ *.libs *.o @@ -24,5 +24,29 @@ profile.txt # Dist libCello* -# VIM related -.clang_complete +# VIM related +.clang_complete + +# benchmark programs +benchmarks/Dict/dict_c +benchmarks/Dict/dict_cello +benchmarks/Dict/dict_cpp +benchmarks/ext/genint +benchmarks/GC/gc_c +benchmarks/GC/gc_cello +benchmarks/GC/gc_cpp +benchmarks/List/list_c +benchmarks/List/list_cello +benchmarks/List/list_cpp +benchmarks/Map/map_c +benchmarks/Map/map_cello +benchmarks/Map/map_cpp +benchmarks/Matmul/matmul_c +benchmarks/Matmul/matmul_cello +benchmarks/Matmul/matmul_cpp +benchmarks/Nbodies/nbodies_c +benchmarks/Nbodies/nbodies_cello +benchmarks/Nbodies/nbodies_cpp +benchmarks/Sudoku/sudoku_c +benchmarks/Sudoku/sudoku_cello +benchmarks/Sudoku/sudoku_cpp From 229e2b0e439b9379294dad3309f2040273a1be82 Mon Sep 17 00:00:00 2001 From: Bill Morgan Date: Sun, 11 Apr 2021 20:34:51 -0500 Subject: [PATCH 4/5] run different benchmark script on Mac -pg doesn't work clang: error: the clang compiler does not support -pg option on versions of OS X 10.9 and later time and echo are different too --- Makefile | 7 +- benchmarks/benchmark.sh | 214 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 220 insertions(+), 1 deletion(-) create mode 100755 benchmarks/benchmark.sh diff --git a/Makefile b/Makefile index e26f982..7ce0e4a 100644 --- a/Makefile +++ b/Makefile @@ -139,10 +139,15 @@ obj/%.o: tests/%.c | obj $(CC) $< -c $(CFLAGS) -o $@ # Benchmarks - +ifeq ($(findstring Darwin,$(PLATFORM)),Darwin) +bench: CFLAGS += -DCELLO_NDEBUG +bench: clean $(STATIC) + cd benchmarks; ./benchmark.sh; cd ../ +else bench: CFLAGS += -DCELLO_NDEBUG -pg bench: clean $(STATIC) cd benchmarks; ./benchmark; cd ../ +endif # Examples diff --git a/benchmarks/benchmark.sh b/benchmarks/benchmark.sh new file mode 100755 index 0000000..2f87589 --- /dev/null +++ b/benchmarks/benchmark.sh @@ -0,0 +1,214 @@ +#!/bin/sh +gcc ./ext/genint.c -o ./ext/genint + +gcc Nbodies/nbodies_c.c -std=c99 -O3 -lm -o Nbodies/nbodies_c +g++ Nbodies/nbodies_cpp.cpp -std=c++11 -O3 -lm -o Nbodies/nbodies_cpp +cc Nbodies/nbodies_cello.c -DCELLO_NDEBUG ../libCello.a -I../include -std=gnu99 -O3 -lm -lpthread -o Nbodies/nbodies_cello +javac Nbodies/nbodies_java.java + +gcc List/list_c.c -Wno-unused-result -I./ext -std=c99 -O3 -lm -o List/list_c +g++ List/list_cpp.cpp -Wno-unused-result -std=c++11 -O3 -lm -o List/list_cpp +cc List/list_cello.c -DCELLO_NDEBUG ../libCello.a -I../include -Wno-unused-result -std=gnu99 -O3 -lm -lpthread -o List/list_cello +javac List/list_java.java + +gcc Dict/dict_c.c -Wno-unused-result -I./ext -std=c99 -O3 -lm -o Dict/dict_c +g++ Dict/dict_cpp.cpp -Wno-unused-result -std=c++11 -O3 -lm -o Dict/dict_cpp +cc Dict/dict_cello.c -DCELLO_NDEBUG ../libCello.a -I../include -Wno-unused-result -std=gnu99 -O3 -lm -lpthread -o Dict/dict_cello +javac Dict/dict_java.java + +gcc Map/map_c.c -Wno-unused-result -I./ext -std=c99 -O3 -lm -o Map/map_c +g++ Map/map_cpp.cpp -Wno-unused-result -std=c++11 -O3 -lm -o Map/map_cpp +cc Map/map_cello.c -DCELLO_NDEBUG ../libCello.a -I../include -Wno-unused-result -std=gnu99 -O3 -lm -lpthread -o Map/map_cello +javac Map/map_java.java + +gcc Sudoku/sudoku_c.c -Wno-unused-result -I./ext -std=c99 -O3 -lm -o Sudoku/sudoku_c +g++ Sudoku/sudoku_cpp.cpp -Wno-unused-result -std=c++11 -O3 -lm -o Sudoku/sudoku_cpp +cc Sudoku/sudoku_cello.c -DCELLO_NDEBUG ../libCello.a -I../include -Wno-unused-result -std=gnu99 -O3 -lm -lpthread -o Sudoku/sudoku_cello +javac Sudoku/sudoku_java.java + +gcc Matmul/matmul_c.c -Wno-unused-result -I./ext -std=c99 -O3 -lm -o Matmul/matmul_c +g++ Matmul/matmul_cpp.cpp -Wno-unused-result -std=c++11 -O3 -lm -o Matmul/matmul_cpp +cc Matmul/matmul_cello.c -DCELLO_NDEBUG ../libCello.a -I../include -Wno-unused-result -std=gnu99 -O3 -lm -lpthread -o Matmul/matmul_cello +javac Matmul/matmul_java.java + +gcc GC/gc_c.c -Wno-unused-result -I./ext -std=c99 -O3 -lm -o GC/gc_c +g++ GC/gc_cpp.cpp -Wno-unused-result -std=c++11 -O3 -lm -o GC/gc_cpp +cc GC/gc_cello.c -DCELLO_NDEBUG ../libCello.a -I../include -std=gnu99 -O3 -lm -lpthread -o GC/gc_cello +javac GC/gc_java.java + +echo +echo "## Garbage Collection" +echo +printf "* C: " +gtime -f "%e" -f "%e" ./GC/gc_c +printf "* C++: " +gtime -f "%e" -f "%e" ./GC/gc_cpp +printf "* Cello: " +gtime -f "%e" -f "%e" ./GC/gc_cello +printf "* Java: " +gtime -f "%e" -f "%e" java -cp ./GC gc_java +printf "* Javascript: " +gtime -f "%e" -f "%e" node GC/gc_javascript.js +printf "* Python: " +gtime -f "%e" -f "%e" python GC/gc_python.py +printf "* Ruby: " +gtime -f "%e" -f "%e" ruby GC/gc_ruby.rb +printf "* Lua: " +gtime -f "%e" -f "%e" lua GC/gc_lua.lua +# printf "* Lua JIT: " +# gtime -f "%e" -f "%e" luajit GC/gc_lua.lua + +# gprof GC/gc_cello > GC/profile.txt +# rm gmon.out + + +echo +echo "## List" +echo +printf "* C: " +gtime -f "%e" -f "%e" ./List/list_c +printf "* C++: " +gtime -f "%e" -f "%e" ./List/list_cpp +printf "* Cello: " +gtime -f "%e" -f "%e" ./List/list_cello +printf "* Java: " +gtime -f "%e" -f "%e" java -cp ./List list_java +printf "* Javascript: " +gtime -f "%e" -f "%e" node List/list_javascript.js +printf "* Python: " +gtime -f "%e" -f "%e" python List/list_python.py +printf "* Ruby: " +gtime -f "%e" -f "%e" ruby List/list_ruby.rb +printf "* Lua: " +gtime -f "%e" -f "%e" lua List/list_lua.lua +# printf "* Lua JIT: " +# gtime -f "%e" -f "%e" luajit List/list_lua.lua + +# gprof List/list_cello > List/profile.txt +# rm gmon.out + +echo +echo "## Map" +echo +printf "* C: " +gtime -f "%e" -f "%e" sh -c './ext/genint | ./Map/map_c' +printf "* C++: " +gtime -f "%e" -f "%e" sh -c './ext/genint | ./Map/map_cpp' +printf "* Cello: " +gtime -f "%e" -f "%e" sh -c './ext/genint | ./Map/map_cello' +printf "* Java: " +gtime -f "%e" -f "%e" sh -c './ext/genint | java -cp ./Map map_java' +printf "* Javascript: " +gtime -f "%e" -f "%e" sh -c './ext/genint | node Map/map_javascript.js' +printf "* Python: " +gtime -f "%e" -f "%e" sh -c './ext/genint | python Map/map_python.py' +printf "* Ruby: " +gtime -f "%e" -f "%e" sh -c './ext/genint | ruby Map/map_ruby.rb' +printf "* Lua: " +gtime -f "%e" -f "%e" sh -c './ext/genint | lua Map/map_lua.lua' +# printf "* Lua JIT: " +# gtime -f "%e" -f "%e" sh -c './ext/genint | luajit Map/map_lua.lua' + +# gprof Map/map_cello > Map/profile.txt +# rm gmon.out + +echo +echo "## NBodies" +echo +printf "* C: " +gtime -f "%e" -f "%e" ./Nbodies/nbodies_c +printf "* C++: " +gtime -f "%e" -f "%e" ./Nbodies/nbodies_cpp +printf "* Cello: " +gtime -f "%e" -f "%e" ./Nbodies/nbodies_cello +printf "* Java: " +gtime -f "%e" -f "%e" java -cp ./Nbodies nbodies_java +printf "* Javascript: " +gtime -f "%e" -f "%e" node Nbodies/nbodies_javascript.js +printf "* Python: " +gtime -f "%e" -f "%e" python Nbodies/nbodies_python.py +printf "* Ruby: " +gtime -f "%e" -f "%e" ruby Nbodies/nbodies_ruby.rb +printf "* Lua: " +gtime -f "%e" -f "%e" lua Nbodies/nbodies_lua.lua +# printf "* Lua JIT: " +# gtime -f "%e" -f "%e" luajit Nbodies/nbodies_lua.lua + +# gprof Nbodies/nbodies_cello > Nbodies/profile.txt +# rm gmon.out + +echo +echo "## Dict" +echo +printf "* C: " +gtime -f "%e" -f "%e" sh -c './ext/genint | ./Dict/dict_c' +printf "* C++: " +gtime -f "%e" -f "%e" sh -c './ext/genint | ./Dict/dict_cpp' +printf "* Cello: " +gtime -f "%e" -f "%e" sh -c './ext/genint | ./Dict/dict_cello' +printf "* Java: " +gtime -f "%e" -f "%e" sh -c './ext/genint | java -cp ./Dict dict_java' +printf "* Javascript: " +gtime -f "%e" -f "%e" sh -c './ext/genint | node Dict/dict_javascript.js' +printf "* Python: " +gtime -f "%e" -f "%e" sh -c './ext/genint | python Dict/dict_python.py' +printf "* Ruby: " +gtime -f "%e" -f "%e" sh -c './ext/genint | ruby Dict/dict_ruby.rb' +printf "* Lua: " +gtime -f "%e" -f "%e" sh -c './ext/genint | lua Dict/dict_lua.lua' +# printf "* Lua JIT: " +# gtime -f "%e" -f "%e" sh -c './ext/genint | luajit Dict/dict_lua.lua' + +# gprof Dict/dict_cello > Dict/profile.txt +# rm gmon.out + +echo +echo "## Sudoku" +echo +printf "* C: " +gtime -f "%e" -f "%e" sh -c './ext/sudoku | ./Sudoku/sudoku_c' +printf "* C++: " +gtime -f "%e" -f "%e" sh -c './ext/sudoku | ./Sudoku/sudoku_cpp' +printf "* Cello: " +gtime -f "%e" -f "%e" sh -c './ext/sudoku | ./Sudoku/sudoku_cello' +printf "* Java: " +gtime -f "%e" -f "%e" sh -c './ext/sudoku | java -cp ./Sudoku sudoku_java' +printf "* Javascript: " +gtime -f "%e" -f "%e" sh -c './ext/sudoku | node Sudoku/sudoku_javascript.js' +printf "* Python: " +gtime -f "%e" -f "%e" sh -c './ext/sudoku | python Sudoku/sudoku_python.py' +printf "* Ruby: " +gtime -f "%e" -f "%e" sh -c './ext/sudoku | ruby Sudoku/sudoku_ruby.rb' +printf "* Lua: " +gtime -f "%e" -f "%e" sh -c './ext/sudoku | lua Sudoku/sudoku_lua.lua' +# printf "* Lua JIT: " +# gtime -f "%e" -f "%e" sh -c './ext/sudoku | luajit Sudoku/sudoku_lua.lua' + +# gprof Sudoku/sudoku_cello > Sudoku/profile.txt +# rm gmon.out + +echo +echo "## Matmul" +echo +printf "* C: " +gtime -f "%e" -f "%e" ./Matmul/matmul_c +printf "* C++: " +gtime -f "%e" -f "%e" ./Matmul/matmul_cpp +printf "* Cello: " +gtime -f "%e" -f "%e" ./Matmul/matmul_cello +printf "* Java: " +gtime -f "%e" -f "%e" java -cp ./Matmul matmul_java +printf "* Javascript: " +gtime -f "%e" -f "%e" node Matmul/matmul_javascript.js +printf "* Python: " +gtime -f "%e" -f "%e" python Matmul/matmul_python.py +printf "* Ruby: " +gtime -f "%e" -f "%e" ruby Matmul/matmul_ruby.rb +printf "* Lua: " +gtime -f "%e" -f "%e" lua Matmul/matmul_lua.lua +# printf "* Lua JIT: " +# gtime -f "%e" -f "%e" luajit Matmul/matmul_lua.lua + +# gprof Matmul/matmul_cello > Matmul/profile.txt +# rm gmon.out + From 783733f03b5875e650431fb866aa74e37a082f43 Mon Sep 17 00:00:00 2001 From: Bill Morgan Date: Sun, 11 Apr 2021 20:37:18 -0500 Subject: [PATCH 5/5] add -O3 to benchmark build --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 7ce0e4a..45bb310 100644 --- a/Makefile +++ b/Makefile @@ -140,11 +140,11 @@ obj/%.o: tests/%.c | obj # Benchmarks ifeq ($(findstring Darwin,$(PLATFORM)),Darwin) -bench: CFLAGS += -DCELLO_NDEBUG +bench: CFLAGS += -DCELLO_NDEBUG -O3 bench: clean $(STATIC) cd benchmarks; ./benchmark.sh; cd ../ else -bench: CFLAGS += -DCELLO_NDEBUG -pg +bench: CFLAGS += -DCELLO_NDEBUG -pg -O3 bench: clean $(STATIC) cd benchmarks; ./benchmark; cd ../ endif