Created
May 9, 2010 22:44
-
-
Save JosephPecoraro/395477 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
// So this will run in a browser as well as a shell. | |
if (this.window) window.print = function(s) { console.log(s); } | |
var TOTAL = 1e6; | |
var str = "color: red"; | |
// Test with regex | |
(function() { | |
var start = Date.now(); | |
for (var i=0; i<TOTAL; ++i) { | |
var match = str.match(/[^:]+/); | |
if (match) | |
match[0]; | |
} | |
var end = Date.now(); | |
print(end-start+'ms'); | |
})(); | |
// Test with substring | |
(function() { | |
var start = Date.now(); | |
for (var i=0; i<TOTAL; ++i) { | |
var index = str.indexOf(':'); | |
if (index >= 0) | |
str.substring(0, str.indexOf(':')); | |
} | |
var end = Date.now(); | |
print(end-start+'ms'); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment