Skip to content

Instantly share code, notes, and snippets.

@kangax
Created September 23, 2009 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kangax/c36ea485926806020024 to your computer and use it in GitHub Desktop.
Save kangax/c36ea485926806020024 to your computer and use it in GitHub Desktop.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title></title>
</head>
<body>
<script type="text/javascript">
(function(){
var o1 = {
o2: {
o3: {
o41: 1,
o42: false
}
}
};
function testWith() {
with (o1.o2.o3) {
o41;
o42;
}
}
function testFullPropAccess() {
o1.o2.o3.o41
o1.o2.o3.o42;
}
function testAliasedPropAccess() {
var o = o1.o2.o3;
o.o41;
o.o42;
}
var lim = 500000;
var t = new Date();
for (var i=lim; i--; ) {
testWith();
}
var t1 = new Date() - t;
t = new Date();
for (var i=lim; i--; ) {
testFullPropAccess();
}
var t2 = new Date() - t;
t = new Date();
for (var i=lim; i--; ) {
testAliasedPropAccess();
}
var t3 = new Date() - t;
document.write('t1: ' + t1 + 'ms<br>t2: ' + t2 + 'ms<br>t3: ' + t3 + 'ms');
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment