Created
January 31, 2010 08:54
-
-
Save bga/290973 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
// Sorry. Hack fail :( | |
// "Speedup" in opera and chrome because bugs in webkit (compile return undefined) | |
// and opera (invalid regexp object return). | |
// Giant thanks to @jdalton and @diegoperini | |
var i,n=20000; | |
var i=0; | |
var t=""; | |
for(i=0;i<10000;++i) | |
t+=" a"; | |
var d=+(new Date()); | |
for(i=0;i<n;++i) | |
t.replace(/\s+/,""); | |
alert("1: "+(+(new Date())-d)); | |
var re=/\s+/; | |
var d=+(new Date()); | |
for(i=0;i<n;++i) | |
t.replace(re,""); | |
alert("2: "+(+(new Date())-d)); | |
var re=new RegExp(/\s+/); | |
var d=+(new Date()); | |
for(i=0;i<n;++i) | |
t.replace(re,""); | |
alert("3: "+(+(new Date())-d)); | |
var re=/\s+/.compile(/\s+/); | |
var d=+(new Date()); | |
for(i=0;i<n;++i) | |
t.replace(re,""); | |
alert("4: "+(+(new Date())-d)); | |
/* | |
Chrome | |
1: 1017 | |
2: 971 | |
3: 972 | |
4: 590 | |
ff3.6 | |
1: 478ms | |
2: 474ms | |
3: 470ms | |
4: 483ms | |
ie7 | |
1: 671 | |
2: 641 | |
3: 641 | |
4: 661 | |
opera 10.10 | |
1: 1342 | |
2: 1342 | |
3: 1221 | |
4: 521 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment