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 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Mobile Safari/537.36
Browser:
Chrome Mobile 126
Operating system:
Android
Device Platform:
Mobile
Date tested:
one year ago
Test name
Executions per second
Loop
3259180.8 Ops/sec
DataView
1374523.1 Ops/sec
Hex
923228.0 Ops/sec
Loop2
2321812.2 Ops/sec
Split
9455548.0 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]))