Skip to content

Instantly share code, notes, and snippets.

@whizzter
Created January 2, 2019 02:58
Show Gist options
  • Save whizzter/b2712682a9a0f0ee26ab909fda20981f to your computer and use it in GitHub Desktop.
Save whizzter/b2712682a9a0f0ee26ab909fda20981f to your computer and use it in GitHub Desktop.
JavaScript property value rotation microbenchmark
// 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