Hex to RGB (v7)

Revision 7 of this benchmark created on


Setup

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;
  }

Test runner

Ready to run.

Testing in
TestOps/sec
hexToRgb1
var test;
for(var i = 0; i < data.length; i++)
{
    test = hexToRgb1(data[i]);
}
ready
hexToRgb2
var test;
for(var i = 0; i < data.length; i++)
{
    test = hexToRgb2(data[i]);
}
ready
hexToRgb3
var test;
for(var i = 0; i < data.length; i++)
{
    test = hexToRgb3(data[i]);
}
ready
hexToRgb4
var test;
for(var i = 0; i < data.length; i++)
{
    test = hexToRgb4(data[i]);
}
ready

Revisions

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