Skip to content

Instantly share code, notes, and snippets.

@eligrey
Created April 9, 2010 01:57
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 eligrey/360793 to your computer and use it in GitHub Desktop.
Save eligrey/360793 to your computer and use it in GitHub Desktop.
<!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