HTML Preparation code:
AخA
 
1
<!--your preparation HTML code goes here-->
Script Preparation code:
x
 
function bigIntToBigEndianBytesLoopParseInt(value) {
    const hex = value.toString(16).padStart(16, '0');
    const bytes = new Uint8Array(8);
    for (let i = 0; i < 8; i++) {
        bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
    }
    return bytes;
}
function bigIntToBigEndianBytesLoopConstructor(value) {
    const hex = value.toString(16).padStart(16, '0');
    const bytes = new Uint8Array(8);
    for (let i = 0; i < 8; i++) {
        bytes[i] = Number(hex.slice(i * 2, i * 2 + 2), 16);
    }
    return bytes;
}
function bigIntToBigEndianBytesDataView(value) {
    const buf = new ArrayBuffer(8);
    const view = new DataView(buf);
    view.setBigUint64(0, value);
    return new Uint8Array(buf);
}
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;
}
function bigIntToUint8ArrayDirectParseInt(value) {
    const result = new Uint8Array(8);
    result[7] = parseInt(value & 0xffn);
    result[6] = parseInt((value >> 8n) & 0xffn);
    result[5] = parseInt((value >> 16n) & 0xffn);
    result[4] = parseInt((value >> 24n) & 0xffn );
    result[3] = parseInt((value >> 32n) & 0xffn);
    result[2] = parseInt((value >> 40n) & 0xffn);
    result[1] = parseInt((value >> 48n) & 0xffn);
    result[0] = parseInt((value >> 56n) & 0xffn);
    return result;
}
Tests:
  • Loop ParseInt

     
    bigIntToBigEndianBytesLoopParseInt(32149814014n)
  • Loop Constructor

     
    bigIntToBigEndianBytesLoopConstructor(32149814014n)
  • DataView

     
    bigIntToBigEndianBytesDataView(32149814014n)
  • Direct Constructor

     
    bigIntToUint8ArrayDirectConstructor(32149814014n)
  • Direct ParseInt

     
    bigIntToUint8ArrayDirectParseInt(32149814014n)
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Loop ParseInt
    Loop Constructor
    DataView
    Direct Constructor
    Direct ParseInt

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 4 months ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:134.0) Gecko/20100101 Firefox/134.0
Firefox 134 on Windows
View result in a separate tab
Test name Executions per second
Loop ParseInt 2849222.8 Ops/sec
Loop Constructor 1508101.4 Ops/sec
DataView 2983838.0 Ops/sec
Direct Constructor 5215165.5 Ops/sec
Direct ParseInt 2909482.8 Ops/sec