decode

Benchmark created on


Setup

const color=['black',"brown","red","orange","yellow","green","blue","violet","grey","white"]
const colorMap={'black':0,"brown":1,"red":2,"orange":3,"yellow":4,"green":5,"blue":6,"violet":7,"grey":8,"white":9}

const decodedValue1 = (code1) => Number(String(color.indexOf(code1[0]))+String(color.indexOf(code1[1])))
const decodedValue2 = (code1) => color.indexOf(code1[0])*10 +color.indexOf(code1[1])
const decodedValue3 = (code1) => color[code1[0]]*10 +color[code1[1]]

Test runner

Ready to run.

Testing in
TestOps/sec
string
decodedValue1(['white', 'green'])
ready
number
decodedValue2(['white', 'green'])
ready
map
decodedValue3(['white', 'green'])
ready

Revisions

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