Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Benchmark (フィボナッチ数列42まで)
#!/usr/bin/env bash
remove() {
if [ -e $1 ]; then
rm -rf $1
fi
}
remove c
echo "c (not optimized) compile"
gcc -v
time gcc -o c c.c
echo "c (not optimized)"
time ./c > /dev/null
echo
remove c2
echo "c (optimized) compile"
time gcc -O2 -o c2 c.c
echo "c (optimized)"
time ./c2 > /dev/null
echo
# remove cpp
# echo "cpp (not optimized) compile"
# time g++ -o cpp cpp.cpp
# echo "cpp (not optimized)"
# time ./cpp > /dev/null
# echo
# remove cpp2
# echo "cpp (optimized) compile"
# time g++ -O2 -o cpp2 cpp.cpp
# echo "cpp (optimized)"
# time ./cpp2 > /dev/null
# echo
echo "dart"
dart --version
time dart dart.dart > /dev/null
echo
remove dart.js
remove dart.js.deps
remove dart.js.map
echo "dart to js compile"
dart2js --version
time dart2js -o dart.js dart.dart
echo "js by dart"
node -v
time node dart.js > /dev/null
echo
remove go
echo "go compile"
go version
time go build go.go
echo "go"
time ./go > /dev/null
echo
echo "javascript (node)"
node -v
time node js.js > /dev/null
echo
echo "julia"
julia -v
time julia julia.jl > /dev/null
echo
echo "lua 5.2"
lua5.2 -v
time lua5.2 lua.lua > /dev/null
echo
# remove luac.out
# echo "lua 5.2 compile"
# time luac5.2 lua.lua
# echo
echo
echo "luajit"
luajit -v
time luajit lua.lua > /dev/null
echo
remove nimcache
remove nim
echo "nim (debug) compile"
nim -v
time nim c nim.nim > /dev/null
echo "nim (debug)"
time ./nim > /dev/null
echo
remove nimcache
remove nim
echo "nim (release) compile"
time nim c -d:release nim.nim > /dev/null
echo "nim (release)"
time ./nim > /dev/null
echo
echo "Python (v2.7)"
/usr/bin/python2.7 -V
time /usr/bin/python2.7 python.py > /dev/null
echo "pypy"
pypy -V
time pypy python.py > /dev/null
echo
echo "Python (v3.4)"
/usr/bin/python3.4 -V
time /usr/bin/python3.4 python.py > /dev/null
echo "pypy3"
pypy3 -V
time pypy3 python.py > /dev/null
echo
echo "Ruby (v1.9)"
ruby -v
time ruby ruby.rb > /dev/null
echo
echo "Ruby (v2.0)"
ruby2.0 -v
time ruby2.0 ruby.rb > /dev/null
echo
remove rust
echo "Rust (not optimized) compile"
rustc --version
time rustc rust.rs
echo "Rust (not optimized)"
time ./rust > /dev/null
echo
remove rust
echo "Rust (optimized) compile"
time rustc -O rust.rs
echo "Rust (optimized)"
time ./rust > /dev/null
echo
# echo "Vim script"
# nice -n -15 time vim --noplugin -u ./vim.vim -c "q"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment