Created
January 2, 2019 02:58
-
-
Save whizzter/b2712682a9a0f0ee26ab909fda20981f to your computer and use it in GitHub Desktop.
JavaScript property value rotation microbenchmark
This file contains 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
// node.js is about 4-5x faster than JS->C compiler and 470x faster than duktape | |
var obj1,obj2; | |
obj1={x:12,y:34}; | |
obj2={x:56,y:78}; | |
var start,stop; | |
console.log("Warmup"); | |
rot(obj1,obj2); | |
console.log("Bench"); | |
start=new Date().valueOf(); | |
rot(obj1,obj2); | |
stop=new Date().valueOf(); | |
console.log(obj1.x+" "+obj1.y+" "+obj2.x+" "+obj2.y); | |
console.log(stop-start); | |
function rot(a,b) { | |
var c; | |
var tmp; | |
console.log("In rot?!"); | |
c=1; | |
while(c<10000000) { | |
tmp=a.x; | |
a.x=a.y; | |
a.y=b.x; | |
b.x=b.y; | |
b.y=tmp; | |
c=c+1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment