Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
BigInt to BigEndian Bytes (extended by trincot, v3)
(version: 1)
Comparing performance of:
Direct Constructor vs With split vs With split and forward assignment
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
function bigIntToUint8ArrayDirectConstructor(value) { const result = new Uint8Array(8); result[7] = Number(value & 0xffn); result[6] = Number((value >> 8n) & 0xffn); result[5] = Number((value >> 16n) & 0xffn); result[4] = Number((value >> 24n) & 0xffn); result[3] = Number((value >> 32n) & 0xffn); result[2] = Number((value >> 40n) & 0xffn); result[1] = Number((value >> 48n) & 0xffn); result[0] = Number((value >> 56n) & 0xffn); return result; } // Added by trincot: first split BigInt into two numbers (32 bit), then work with those only function bigIntToUint8ArrayDirectConstructor2(value) { const result = new Uint8Array(8); const low = Number(value & 0xffffffffn); const high = Number(value >> 32n); result[7] = low & 0xff; result[6] = (low >>> 8) & 0xff; result[5] = (low >>> 16) & 0xff; result[4] = low >>> 24; result[3] = high & 0xff; result[2] = (high >>> 8) & 0xff; result[1] = (high >>> 16) & 0xff; result[0] = high >>> 24; return result; } // Forward assignment instead of backward function bigIntToUint8ArrayDirectConstructor3(value) { const result = new Uint8Array(8); const low = Number(value & 0xffffffffn); const high = Number(value >> 32n); result[0] = high >>> 24; result[1] = (high >>> 16) & 0xff; result[2] = (high >>> 8) & 0xff; result[3] = high & 0xff; result[4] = low >>> 24; result[5] = (low >>> 16) & 0xff; result[6] = (low >>> 8) & 0xff; result[7] = low & 0xff; return result; }
Tests:
Direct Constructor
bigIntToUint8ArrayDirectConstructor(32149814014n)
With split
bigIntToUint8ArrayDirectConstructor2(32149814014n)
With split and forward assignment
bigIntToUint8ArrayDirectConstructor3(32149814014n)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Direct Constructor
With split
With split and forward assignment
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
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 Edg/131.0.0.0
Browser/OS:
Chrome 131 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Direct Constructor
6574462.5 Ops/sec
With split
11788106.0 Ops/sec
With split and forward assignment
11554508.0 Ops/sec
Related benchmarks:
array buffer to hex conversion
array buffer to hex conversion 2
JS BigInt To Uint8Array
Big Int to Uint8Array
BigInt to BigEndian Bytes
BigInt to BigEndian Bytes - with AB
Bytes to BigInt64
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?