Skip to content

Instantly share code, notes, and snippets.

@jdonaldson
Last active January 19, 2017 16:16
Show Gist options
  • Save jdonaldson/7e2b8039ff42958091904f663ef3376b to your computer and use it in GitHub Desktop.
Save jdonaldson/7e2b8039ff42958091904f663ef3376b to your computer and use it in GitHub Desktop.
Quick and dirty array benchmark
-cmd echo "---------LUAJIT-----------"
-main Main
-lua out.lua
-cmd luajit out.lua
--next
-cmd echo "---------NODE-----------"
-main Main
-js out.js
-D nodejs
-cmd node out.js
--next
-cmd echo "---------CPP-----------"
-main Main
-cpp outcpp
-cmd ./outcpp/Main
--next
-cmd echo "-------HL (bytecode)-------"
-main Main
-hl out.hl
-cmd hl out.hl
--next
-cmd echo "-------Python--------"
-main Main
-python out.py
-cmd python3 out.py
import haxe.Timer;
class Main {
static function main() {
var num = 10000000;
var indexcnt =10000 ;
var k = [];
var junk : Array<Dynamic> = [];
var start = Timer.stamp();
walltime(function(){
for (i in 0...num){
k.push(i);
}
}, ' push $num');
var d : Int = 0;
walltime(function(){
for (i in k){
d = Std.random(num);
}
}, 'iterate $num');
junk.push(d);
var m : Array<Int>;
walltime(function(){
m = k.map(function(x) return x++);
}, 'map $num');
junk.push(m.length);
var t = 0;
walltime(function(){
for (x in 0...indexcnt){
var x2 = Std.random(indexcnt);
t = k.indexOf(x2);
}
}, 'indexOf $indexcnt');
junk.push(t);
walltime(function(){
k.reverse();
}, 'reverse $num');
trace('ignore this $junk');
trace(Timer.stamp() - start + " is the total time");
}
static function walltime(f : Void->Void, desc){
var s = Timer.stamp();
f();
trace(Timer.stamp() - s + ' is the time for $desc');
}
}
@jdonaldson
Copy link
Author

jdonaldson commented Jan 18, 2017

Here's the results from the latest run :

---------LUAJIT-----------
Main.hx:50: 0.15220999717712 is the time for  push 10000000
Main.hx:50: 0.059314966201782 is the time for iterate 10000000
Main.hx:50: 0.16914892196655 is the time for map 10000000
Main.hx:50: 0.10476303100586 is the time for indexOf 10000
Main.hx:50: 0.012661933898926 is the time for reverse 10000000
Main.hx:42: ignore this [2729675,10000000,2799]
Main.hx:44: 0.54048299789429 is the total time
---------NODE-----------
0.21399998664855957 is the time for  push 10000000
0.11100006103515625 is the time for iterate 10000000
1.1410000324249268 is the time for map 10000000
0.04999995231628418 is the time for indexOf 10000
0.09599995613098145 is the time for reverse 10000000
ignore this [5895568,10000000,926]
1.6159999370574951 is the total time
---------CPP-----------
Main.hx:50: 0.140476942062378 is the time for  push 10000000
Main.hx:50: 0.19896388053894 is the time for iterate 10000000
Main.hx:50: 0.338688135147095 is the time for map 10000000
Main.hx:50: 0.0155551433563232 is the time for indexOf 10000
Main.hx:50: 0.00520086288452148 is the time for reverse 10000000
Main.hx:42: ignore this [9264574,10000000,5898]
Main.hx:44: 0.699034929275513 is the total time
-------HL (bytecode)-------
Main.hx:50: 0.134882926940918 is the time for  push 10000000
Main.hx:50: 0.128238201141357 is the time for iterate 10000000
Main.hx:50: 1.36843299865723 is the time for map 10000000
Main.hx:50: 0.114686965942383 is the time for indexOf 10000
Main.hx:50: 0.0333189964294434 is the time for reverse 10000000
Main.hx:42: ignore this [8287868,10000000,347]
Main.hx:44: 1.78324198722839 is the total time
-------Python--------
1.4555047100002412 is the time for  push 10000000
3.7256543330004206 is the time for iterate 10000000
5.396159459996852 is the time for map 10000000
4.936570507998113 is the time for indexOf 10000
0.02978982600325253 is the time for reverse 10000000
ignore this [3722846,10000000,3570]
15.543854118994204 is the total time
haxelib run hxjava hxjava_build.txt --haxe-version 3400 --feature-level 1
javac "-sourcepath" "src" "-d" "obj" "-g:none" "@cmd"
-------Java--------
Main.hx:50: 2.390000104904175 is the time for  push 10000000
Main.hx:50: 0.2090001106262207 is the time for iterate 10000000
Main.hx:50: 3.072999954223633 is the time for map 10000000
Main.hx:50: 0.07300019264221191 is the time for indexOf 10000
Main.hx:50: 0.018999814987182617 is the time for reverse 10000000
Main.hx:42: ignore this [5791781,10000000,3650]
Main.hx:44: 5.766999959945679 is the total time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment