Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Hex convertion : Mapping vs Range
Which one is the faster for hex conversion : testing a range of retrieving a value ? See https://url.spec.whatwg.org/#percent-encoded-bytes
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0
Browser:
Firefox 124
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
Mapping
101137.2 Ops/sec
Range
264705.0 Ops/sec
Script Preparation code:
a = [...Array(1024)].map(_ => Math.floor(Math.random()*256))
Tests:
Mapping
let d = 0; for (const b of a) { const c = b < 0x30 || b > 0x66 ? null // fast fail : [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, null, null, null, null, null, null, null, // :;<=>?@ 10, 11, 12, 13, 14, 15, // ABCDEF null, null, null, null, null, null, // GHIJKL null, null, null, null, null, null, null, // MNOPQRS null, null, null, null, null, null, null, // TUVWXYZ null, null, null, null, null, null, // [\]^_` 10, 11, 12, 13, 14, 15, // abcdef ][b - 0x30]; if (c !== null) { d += c; } }
Range
let d = 0; for (const b of a) { const c = b < 0x30 || b > 0x66 ? null // fast fail : b <= 0x39 // 0-9 ? b - 0x30 : b >= 0x41 && b <= 0x46 // A-F ? b - 0x37 // 0x41 - 10 : b >= 0x61 // a-f ? b - 0x57 // 0x61 - 10 : null; if (c !== null) { d += c; } }