$ alias time='/usr/bin/time -f "\nCPU: %Us\tReal: %es\tRAM: %MKB"'
$ php -v
PHP 7.4.3 (cli) (built: Oct 6 2020 15:47:56) ( NTS )
$ time php assoc.php
637912 641149 67002
3808703 14182513 2343937
CPU: 1.25s Real: 1.34s RAM: 190644KB
$ python3 -V
Python 3.8.5
$ time python3 dictionary.py
637912 641149 67002
3808703 14182513 2343937
CPU: 5.33s Real: 5.47s RAM: 314564KB
$ ruby3.0 -v
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux-gnu]
$ time ruby3.0 --jit hash.rb
637912 641149 67002
3808703 14182513 2343937
CPU: 6.50s Real: 5.94s RAM: 371832KB
$ go version
go version go1.14.7 linux/amd64
$ time go run map.go
637912 641149 67002
3808703 14182513 2343937
CPU: 1.79s Real: 1.56s RAM: 257440KB
$ node -v
v14.15.2
$ time node object.js
637912 641149 67002
3808703 14182513 2343937
CPU: 2.24s Real: 2.21s RAM: 326636KB
$ luajit -v
LuaJIT 2.1.0-beta3 -- Copyright (C) 2005-2017 Mike Pall. http://luajit.org/
$ time luajit table.lua
637912 641149 67002
3808703 14182513 2343937
CPU: 4.11s Real: 4.22s RAM: 250828KB
$ dart --version
Dart SDK version: 2.10.4 (stable) (Unknown timestamp) on "linux_x64"
$ time dart map.dart
637912 641149 67002
3808703 14182513 2343937
CPU: 2.99s Real: 2.91s RAM: 385496KB
$ v version
V 0.2 36dcace
$ time v run map.v
637912, 641149, 67002
3808703, 14182513, 2343937
CPU: 4.79s Real: 5.28s RAM: 1470668KB
$ tcc -v
tcc version 0.9.27 (x86_64 Linux)
$ time tcc -run uthash.c
637912 641149 67002
3808703 14182513 2343937
Command exited with non-zero status 25
CPU: 2.52s Real: 2.61s RAM: 291912KB
$ export GOPHERJS_GOROOT="$(go1.12.16 env GOROOT)"
$ npm install --global source-map-support
$ goperjs version
GopherJS 1.12-3
$ time gopherjs
637912 641149 67002
3808703 14182513 2343937
CPU: 14.13s Real: 12.01s RAM: 597712KB
$ java -version
java version "14.0.2" 2020-07-14
Java(TM) SE Runtime Environment (build 14.0.2+12-46)
Java HotSpot(TM) 64-Bit Server VM (build 14.0.2+12-46, mixed mode, sharing)
$ time java hashmap.java
637912 641149 67002
3808703 14182513 2343937
CPU: 5.18s Real: 1.63s RAM: 545412KB
The result shows a huge improvement for PHP since the old 5.4. NodeJS also huge improvement compared to old 0.10. The rest is quite bit the same. Also please keep note that Golang and V includes build/compile time not just run duration, and it seems V performance really bad when it comes to string operations (the compile itself really fast, less than 1s for 36dcace -- using gcc 9.3.0).
Next we're gonna benchmark comb sort implementation. But this time we use jit version of ruby 2.7, since it's far way faster (19s vs 26s and 58s vs 66s for string benchmark), for ruby 3.0 we always use jit version since it's faster than non-jit. In case for C (TCC) which doesn't have built-in associative array, I used uthash, because it's the most popular. TinyGo does not complete first benchmark after more than 1000s, sometimes segfault. XS Javascript engine failed to give correct result, engine262 also failed to finish within 1000s.
Golang still the winner (obviously, since it's compiled), then Nim (Compiled), next best JIT or interpreter is NodeJS, Crystal (Compiled, not JIT), v8, followed Java, by TCC (Compiled) Dart, PyPy, V (Compiled, not JIT), LuaJIT, PHP, Ruby, and Python3. The recap spreadsheet can be accessed here.
FAQ:
1. Why you measure the compile duration too? because developer experience also important (feedback loop), at least for me.
2. Why not warming up the VM first? each implementation have it's own advantage and disadvantage.
3. Why there's no C++, VB.NET, C#, D, Object-Pascal? don't want to compile things (since there's no build and run command in one flag).
4. Why there's no Kotlin, Scala, Rust, Pony, Swift, Groovy, Julia, Crystal, or Zig? Too lazy to add :3 you can contribute tho (create a pull request, then I'll run the benchmark again as preferabbly as there's precompiled binary/deb/apt/ppa repository for the compiler/interpreter).
Contributors: ilmanzo (Nim, Crystal, D)