rgbToHex

Benchmark created on


Setup

const rgbToHex1 = (r, g, b) =>
  ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)
  
const rgbToHex2 = (r, g, b) =>
  ((r << 16) + (g << 8) + b).toString(16).padStart(6, "0")

Test runner

Ready to run.

Testing in
TestOps/sec
rgbToHex1
console.log(rgbToHex1(0,0,0))
console.log(rgbToHex1(100,255,50))
console.log(rgbToHex1(40,205,190))
ready
rgbToHex2
console.log(rgbToHex2(0,0,0))
console.log(rgbToHex2(100,255,50))
console.log(rgbToHex2(40,205,190))
ready

Revisions

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