Created
July 30, 2011 13:33
-
-
Save hns/1115532 to your computer and use it in GitHub Desktop.
micro-benchmark for property access
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
function bench(x) { | |
for (var i = 0; i < 10000000; i++) { | |
if (x.foo) x.baz; | |
if (x.bar) x.mur; | |
if (x.dng) x.foo; | |
if (x.baz) x.bar; | |
if (x.mur) x.dng; | |
} | |
} | |
if (typeof console === "undefined") console = {log: print}; | |
var obj = { | |
foo: "foo", | |
bar: "bar", | |
dng: "dng", | |
baz: "baz", | |
mur: "mur" | |
}; | |
for (var k = 0; k < 10; k++) { | |
var start = new Date().getTime(); | |
bench(obj); | |
console.log(new Date().getTime() - start); | |
} |
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
hannes@t61:~/git/rhino$ node -v | |
v0.5.3-pre | |
hannes@t61:~/git/rhino$ node getprop.js | |
740 | |
738 | |
738 | |
739 | |
738 | |
737 | |
740 | |
738 | |
738 | |
738 | |
hannes@t61:~/git/rhino$ java -version | |
java version "1.7.0" | |
Java(TM) SE Runtime Environment (build 1.7.0-b147) | |
Java HotSpot(TM) Server VM (build 21.0-b17, mixed mode) | |
hannes@t61:~/git/rhino$ java -jar build/rhino1_7R3/js.jar getprop.js | |
817 | |
748 | |
742 | |
783 | |
730 | |
730 | |
730 | |
730 | |
729 | |
733 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is on a 3 year old thinkpad with current ubuntu and 32 bit os and jvm. Are you using the latest version from the invokedynamic branch? Oh, and i it's the server HotSpot VM of course (as shown in the version info)
I'd like to repeat what I said in my posting to the mailing list - this benchmark doesn't have any significance for real world code. In fact I'd even say it is slightly disappointing.