Created
April 9, 2010 01:57
-
-
Save eligrey/360793 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> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Scope variable profiling</title> | |
<script type="text/javascript" src="http://gist.github.com/186308.txt"></script> | |
</head> | |
<body> | |
<div id="results"></div> | |
<script type="application/javascript; version=1.8"> | |
"use strict"; | |
var x; | |
(function () { | |
var | |
globalScope = new Timer, | |
funcScope = new Timer, | |
blockScope = new Timer, | |
sharpScope = new Timer, | |
iterations = 1000000, | |
docTitle = document.title, | |
results = document.getElementById("results"); | |
document.title += " (In Progress)"; | |
globalScope.profile(function () { | |
1 && ( | |
x = [], | |
x.push(x, x, x) | |
); | |
}, iterations); | |
funcScope.profile(function () { | |
var x; | |
1 && ( | |
x = [], | |
x.push(x, x, x) | |
); | |
}, iterations); | |
blockScope.profile(function () { | |
if (1) { | |
let x = []; | |
x.push(x, x, x); | |
} | |
}, iterations); | |
sharpScope.profile(function () { | |
1 && (#1=[ | |
#1#, | |
#1#, | |
#1# | |
]); | |
}, iterations); | |
results.appendChild(document.createElement("div")) | |
.appendChild(document.createTextNode("global scope: " + globalScope.milliseconds() + "ms")); | |
results.appendChild(document.createElement("div")) | |
.appendChild(document.createTextNode("function scope: " + funcScope.milliseconds() + "ms")); | |
results.appendChild(document.createElement("div")) | |
.appendChild(document.createTextNode("block scope: " + blockScope.milliseconds() + "ms")); | |
results.appendChild(document.createElement("div")) | |
.appendChild(document.createTextNode("sharp scope: " + sharpScope.milliseconds() + "ms")); | |
document.title = docTitle + " (Complete)"; | |
}()); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment