Created
August 24, 2010 14:45
-
-
Save bga/547670 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
// cache from global scope | |
var _parseInt = this.parseInt; | |
_speedTest( | |
[ | |
function(n) | |
{ | |
var r, g, b, s = '#aabbcc'; | |
var i = n; while(i--) | |
{ | |
var h = _parseInt(s.slice(1), 16); | |
r = (h >>> 16) /* & 0xff */; | |
g = (h >>> 8) & 0xff; | |
b = (h ) & 0xff; | |
} | |
}, | |
function(n) | |
{ | |
var r, g, b, s = '#aabbcc'; | |
var i = n; while(i--) | |
{ | |
var h = +('0x' + s.slice(1)); | |
r = (h >>> 16) /* & 0xff */; | |
g = (h >>> 8) & 0xff; | |
b = (h ) & 0xff; | |
} | |
}, | |
function(n) | |
{ | |
var r, g, b, s = '#aabbcc'; | |
var i = n; while(i--) | |
{ | |
r = _parseInt(s.substr(1, 2), 16); | |
g = _parseInt(s.substr(3, 2), 16); | |
b = _parseInt(s.substr(5, 2), 16); | |
} | |
} | |
], | |
1000000 | |
); | |
/* | |
chrome5 1000000 | |
0: 782 ms | |
1: 999 ms | |
2: 2143 ms | |
opera 10.60 1000000 | |
0: 2041 ms | |
1: 2499 ms | |
2: 4674 ms | |
ie7 1000000/10 | |
0: 1171 ms | |
1: 1002 ms | |
2: 3034 ms | |
ff3.6 1000000 | |
0: 1985 ms | |
1: 2907 ms | |
2: 4945 ms | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@GarrettS by analogy
var h = parseInt(s.slice(1), 16);
var r = 0x11((h >>> 8) );
var g = 0x11_((h >>> 4) & 0xf);
var b = 0x11*((h ) & 0xf);