Test name | Executions per second |
---|---|
Bit Shift with Substring | 9564297.0 Ops/sec |
String Concat | 5699835.0 Ops/sec |
Bit Shift with Slice | 9682332.0 Ops/sec |
var r = 1;
var g = 255;
var b = 128;
var hex = function (x) {
x = x.toString(16);
return x.length === 1 ? '0' + x : x;
};
let test = `#${(0x1000000 + (r << 16) + (g << 8) + b).toString(16).substring(1,7)}`;
let test = `#${hex(r)}${hex(g)}${hex(b)}`;
let test = `#${(0x1000000 + (r << 16) + (g << 8) + b).toString(16).slice(1)}`;