rgbToHex (v3)

Revision 3 of this benchmark created on


Setup

const rgbToHex3 = (r, g, b) =>
  (0x1000000 + (r << 16) + (g << 8) + b).toString(16).slice(1)

const rgbToHex2 = (r, g, b) =>
  ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)

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

Test runner

Ready to run.

Testing in
TestOps/sec
rgbToHex1
window.a = rgbToHex1(0,0,0)
window.b = rgbToHex1(100,255,50)
window.c = rgbToHex1(40,205,190)
ready
rgbToHex2
window.a = rgbToHex2(0,0,0)
window.b = rgbToHex2(100,255,50)
window.c = rgbToHex2(40,205,190)
ready
rgbToHex3
window.a = rgbToHex3(0,0,0)
window.b = rgbToHex3(100,255,50)
window.c = rgbToHex3(40,205,190)
ready

Revisions

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