Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Color Num to Hex - Bit Shift vs String Concat
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36
Browser:
Chrome 128
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
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
Script Preparation code:
var r = 1; var g = 255; var b = 128; var hex = function (x) { x = x.toString(16); return x.length === 1 ? '0' + x : x; };
Tests:
Bit Shift with Substring
let test = `#${(0x1000000 + (r << 16) + (g << 8) + b).toString(16).substring(1,7)}`;
String Concat
let test = `#${hex(r)}${hex(g)}${hex(b)}`;
Bit Shift with Slice
let test = `#${(0x1000000 + (r << 16) + (g << 8) + b).toString(16).slice(1)}`;