Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Bytes to BigInt64
(version: 7)
Comparing performance of:
Loop vs DataView vs Hex vs Loop2 vs Split
Created:
one year ago
by:
Registered User
Jump to the latest result
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]))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
Loop
DataView
Hex
Loop2
Split
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
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/OS:
Chrome Mobile 126 on Android
View result in a separate tab
Embed
Embed Benchmark Result
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
Related benchmarks:
ArrayBuffer to base64 String
ArrayBuffer to base64 String vs. superhuman
Base64 encode native func vs readAsDataURL()
Convert bytes to binary string
JS BigInt To Uint8Array
BigInt to BigEndian Bytes
BigInt to BigEndian Bytes - with AB
BigInt to BigEndian Bytes (extended by trincot)
BigInt to BigEndian Bytes (extended by trincot, v2)
Comments
Confirm delete:
Do you really want to delete benchmark?