jonathanmarvens-colorShader-001

JavaScript performance comparison

Test case created by Jonathan Barronville

Preparation code

<script>
function isHexColorString(a){"use strict";return"[object String]"!=={}.toString.call(a)?!1:(a=a.trim(),/^[0-9a-f]{6}$/i.test(a)?!0:!1)}

function colorShader1(a,b){"use strict";if(!isHexColorString(a))return null;var c=parseInt(a,16),d={r:(c>>16)+b,g:(255&c)+b,b:(255&c>>8)+b};d.r>255?d.r=255:0>d.r&&(d.r=0),d.g>255?d.g=255:0>d.g&&(d.g=0),d.b>255?d.b=255:0>d.b&&(d.b=0);var e=(d.r<<16|d.g|d.b<<8).toString(16);return 6===e.length?e:Array(6-e.length+1).join("0")+e}

function colorShader2(a,b){"use strict";if(!isHexColorString(a))return null;var c=parseInt(a,16),d={r:(c>>16)+b,g:(255&c)+b,b:(255&c>>8)+b};for(var e in d)({}).hasOwnProperty.call(d,e)&&(d[e]>255?d[e]=255:0>d[e]&&(d[e]=0));var f=(d.r<<16|d.g|d.b<<8).toString(16);return 6===f.length?f:Array(6-f.length+1).join("0")+f}
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
001
colorShader1( '000000', 255 );
pending…
002
colorShader2( '000000', 255 );
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment