Hex to RGB

JavaScript performance comparison

Revision 7 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var data = [];
  for(var i = 0; i < 10000; i++)
  {
      data.push(Math.floor(Math.random() * 16777215).toString(16));
  }
  
  function hexToRgb1(hex) {
      var bigint = parseInt(hex, 16);
      var r = (bigint >> 16) & 255;
      var g = (bigint >> 8) & 255;
      var b = bigint & 255;
      return [r, g, b];
  }
  
  function hexToRgb2(hex) {
      var raw = parseInt(hex, 16);
      return [(raw >> 16) & 255, (raw >> 8) & 255, raw & 255];
  }
  
  function hexToRgb3(hex) {
      raw = parseInt(hex, 16);
      return [(raw >> 16) & 255, (raw >> 8) & 255, raw & 255];
  }
  
  function hexToRgb4(hex) {
      return 5;
  }

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
hexToRgb1
var test;
for(var i = 0; i < data.length; i++)
{
    test = hexToRgb1(data[i]);
}
pending…
hexToRgb2
var test;
for(var i = 0; i < data.length; i++)
{
    test = hexToRgb2(data[i]);
}
pending…
hexToRgb3
var test;
for(var i = 0; i < data.length; i++)
{
    test = hexToRgb3(data[i]);
}
pending…
hexToRgb4
var test;
for(var i = 0; i < data.length; i++)
{
    test = hexToRgb4(data[i]);
}
pending…

Compare results of other browsers

Revisions

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

0 Comments