Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Bytes to BigInt64
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0
Browser:
Firefox 133
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Loop
1851573.2 Ops/sec
DataView
1314711.6 Ops/sec
Hex
1406418.6 Ops/sec
Loop2
1709589.6 Ops/sec
Split
6982706.5 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
function bytesToBigIntLoop(bytes) { let value = 0n; let bits = 8n; for (let i = 0; i < bytes.length; i++) { value = (value << bits) + BigInt(bytes[i]); } return value; } function bytesToBigIntDataView(bytes) { const view = new DataView(bytes.buffer); return view.getBigInt64(0); } function bytesToBigIntHex(bytes) { return BigInt('0x' + bytes.map(byte => byte.toString(16).padStart(2, '0')).join('')) } function bytesToBigIntLoop2(data) { let encoded = 0n; for (let i = 0, l = data.length; i < l; i++) { encoded |= BigInt(data[i]) << BigInt((l - i - 1) * 8); } return encoded; } function bytesToBigIntSplit(data) { let high = 0; high = (high << 8) | data[0]; high = (high << 8) | data[1]; high = (high << 8) | data[2]; high = (high << 8) | data[3]; let low = 0; low = (low << 8) | data[4]; low = (low << 8) | data[5]; low = (low << 8) | data[6]; low = (low << 8) | data[7]; return (BigInt(low) << 32n) | BigInt(high); }
Tests:
Loop
bytesToBigIntLoop(new Uint8Array([255,255,255,0,0,0,0,0]))
DataView
bytesToBigIntDataView(new Uint8Array([255,255,255,0,0,0,0,0]))
Hex
bytesToBigIntHex(new Uint8Array([255,255,255,0,0,0,0,0]))
Loop2
bytesToBigIntLoop2(new Uint8Array([255,255,255,0,0,0,0,0]))
Split
bytesToBigIntSplit(new Uint8Array([255,255,255,0,0,0,0,0]))