Created
December 4, 2013 06:16
-
-
Save jcmoore/7783153 to your computer and use it in GitHub Desktop.
closure performance investigation
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
(function () { | |
var z = 1; | |
function add (x, y) { | |
z = -z; | |
return x + y + z; | |
} | |
function f () { | |
var sum = 0; | |
for (var i = 0; i < 10000; i++) { | |
sum = add(sum, i); | |
} | |
//if (sum != 49995000) throw "argh"; | |
} | |
function measure(f) { | |
var start = new Date().valueOf(); | |
for (var i = 0; i < 100000; i++) { | |
f(); | |
} | |
var end = new Date().valueOf(); | |
print(end - start); | |
} | |
measure(f); // 4.44s+ | |
}) (); | |
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
(function () { | |
var z = 1; | |
var add = function (x, y) { | |
z = -z; | |
return x + y + z; | |
} | |
var f = function () { | |
var sum = 0; | |
for (var i = 0; i < 10000; i++) { | |
sum = add(sum, i); | |
} | |
//if (sum != 49995000) throw "argh"; | |
} | |
function measure(f) { | |
var start = new Date().valueOf(); | |
for (var i = 0; i < 100000; i++) { | |
f(); | |
} | |
var end = new Date().valueOf(); | |
print(end - start); | |
} | |
measure(f); // 4.42s+ | |
}) (); | |
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
//(function () { | |
var z = 1; | |
function add (x, y) { | |
z = -z; | |
return x + y + z; | |
} | |
function f () { | |
var sum = 0; | |
for (var i = 0; i < 10000; i++) { | |
sum = add(sum, i); | |
} | |
//if (sum != 49995000) throw "argh"; | |
} | |
function measure(f) { | |
var start = new Date().valueOf(); | |
for (var i = 0; i < 100000; i++) { | |
f(); | |
} | |
var end = new Date().valueOf(); | |
print(end - start); | |
} | |
measure(f); // 3.63s+ | |
//}) (); | |
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
//(function () { | |
var z = 1; | |
var add = function (x, y) { | |
z = -z; | |
return x + y + z; | |
} | |
var f = function () { | |
var sum = 0; | |
for (var i = 0; i < 10000; i++) { | |
sum = add(sum, i); | |
} | |
//if (sum != 49995000) throw "argh"; | |
} | |
function measure(f) { | |
var start = new Date().valueOf(); | |
for (var i = 0; i < 100000; i++) { | |
f(); | |
} | |
var end = new Date().valueOf(); | |
print(end - start); | |
} | |
measure(f); // 9.70s+ | |
//}) (); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment