Last active
January 19, 2017 16:16
-
-
Save jdonaldson/7e2b8039ff42958091904f663ef3376b to your computer and use it in GitHub Desktop.
Quick and dirty array benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's the results from the latest run :