Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
array buffer to hex conversion 5 methods
convert array buffer to hex
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/131.0.0.0 Safari/537.36
Browser:
Chrome 131
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
directly set
2491597.0 Ops/sec
push values
3310311.5 Ops/sec
buf2hex()
1640268.4 Ops/sec
precomputed ASCII with shift
861354.1 Ops/sec
array prototype map
1204383.1 Ops/sec
Script Preparation code:
var saltVal = crypto.getRandomValues(new Uint8Array(16)); function arrayBufferToHexString(bytes) { bytes = new Uint8Array(bytes); var hex = new Array(bytes.length); for (let i = 0; i < bytes.length; i++) { hex[i] = ("0" + bytes[i].toString(16)).slice(-2); } return hex.join(""); } function bytesToHexString(bytes) { bytes = new Uint8Array(bytes); var hexBytes = []; for (var i = 0; i < bytes.length; i++) { var byteString = bytes[i].toString(16); if (byteString.length < 2) byteString = "0" + byteString; hexBytes.push(byteString); } return hexBytes.join(""); } function buf2hex(buffer) { // buffer is an ArrayBuffer return [...new Uint8Array(buffer)] .map(x => x.toString(16).padStart(2, '0')) .join(''); } function hex(arrayBuffer) { const asciiCodes = new Uint8Array( Array.prototype.map.call( "0123456789abcdef", char => char.charCodeAt() ) ); const buff = new Uint8Array(arrayBuffer); const charCodes = new Uint8Array(buff.length * 2); for (let i = 0; i < buff.length; ++i) { charCodes[i * 2] = asciiCodes[buff[i] >>> 4]; charCodes[i * 2 + 1] = asciiCodes[buff[i] & 0xf]; } return String.fromCharCode(...charCodes); } function hex2(arrayBuffer) { return Array.prototype.map.call( new Uint8Array(arrayBuffer), n => n.toString(16).padStart(2, "0") ).join(""); }
Tests:
directly set
arrayBufferToHexString(saltVal);
push values
bytesToHexString(saltVal)
buf2hex()
buf2hex(saltVal)
precomputed ASCII with shift
hex(saltVal)
array prototype map
hex2(saltVal)