-
-
Save aaronblohowiak/381338 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | |
"http://www.w3.org/TR/html4/loose.dtd"> | |
<head> | |
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> | |
<title>Test</title> | |
</head> | |
<body id="test"> | |
<script> | |
function jaredsCreate(){ | |
(function() { | |
function create(object){ | |
if (object){ | |
create.prototype = object; | |
return new create; | |
} | |
} | |
Object.create || (Object.create = create); | |
})(); | |
}; | |
function crockfordCreate(){ | |
Object.create = function(o){ | |
var F = function(){}; | |
F.prototype = o; | |
return new F(); | |
}; | |
}; | |
function bench(str, f){ | |
t = new Date(); | |
f(); | |
t2 = new Date(); | |
document.write(str+": "+(t2-t)); | |
} | |
function test(){ | |
for (var i=0; i < 100000; i++) { | |
Object.create({}); | |
}; | |
}; | |
crockfordCreate(); | |
bench("crockford", test); | |
document.write("<br/>"); | |
jaredsCreate(); | |
bench("jared", test); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment