Skip to content

Instantly share code, notes, and snippets.

@bga
Created May 30, 2010 15:48
Show Gist options
  • Save bga/419114 to your computer and use it in GitHub Desktop.
Save bga/419114 to your computer and use it in GitHub Desktop.
if(!console.log)
console.log = $jb._log;
console.time = $jb._timerBegin;
console.timeEnd = $jb._timerEnd;
var i, n = 40000,
a = '11111111111111111111111111111111';
console.time("1");
i = n; while(i--)
{
a.split('1').join('2');
}
console.timeEnd("1");
console.time("2");
var re = /1/g;
i = n; while(i--)
{
a.replace(re, '2');
}
console.timeEnd("2");
/*
ff3.6 n *= 16
1: 11717ms
2: 11160ms
2: 11924ms
1: 11113ms
chrome4
1: 1384
2: 152
2: 157
1: 1347
ie7
1: 3395
2: 1011
2: 1592
1: 3355
opera10.53
1: 1159
2: 746
2: 766
1: 1191
*/
if(!console.log)
console.log = $jb._log;
console.time = $jb._timerBegin;
console.timeEnd = $jb._timerEnd;
var i, n = 40000,
a = '111111101111011111011111011111111111';
console.time("1");
i = n; while(i--)
{
a.split('0').join('2');
}
console.timeEnd("1");
console.time("2");
var re = /0/g;
i = n; while(i--)
{
a.replace(re, '2');
}
console.timeEnd("2");
/*
ff3.6
1: 4154ms
2: 3017ms
2: 3420ms
1: 3464ms
chrome4 n *= 10
1: 3832
2: 942
2: 1509
1: 3071
ie7
1: 2453
2: 601
2: 951
1: 2233
opera10.53 n *= 10
1: 3515
2: 2540
2: 3407
1: 2444
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment