Script Preparation code:
x
 
/**
 * Gets a random number between 2 bigInts
 * @param {BigInt} max
 * @param {BigInt} [min=0n]
 * @returns {BigInt}
 */
function randomBetween(max, min = 0n) {
  max = BigInt(max);
  min = BigInt(min);
  if (max < min) {
    [max, min] = [min, max]
  }
  const range = max - min;
  const count = calculatePrecision(range);
  let random = new Array(Number(count))
    .fill(0)
    .map(() => BigInt(Math.floor(Math.random() * (2 ** 32))))
    .map((int, index) => int << (BigInt(index) * 32n))
    .reduce((acc, int) => acc + int, 0n);
  let bitCount = countBits(range);
  let minRandom = random >> ((32n * count) - bitCount);
  if (minRandom > range) return randomBetween(max, min);
  else return minRandom + min;
}
function calculatePrecision(range) {
  const result = range >> 32n;
  if (result >= 1n) {
    return calculatePrecision(result) + 1n;
  }
  return 1n;
}
function countBits(range) {
  const result = range >> 1n;
  if (result >= 1n) {
    return countBits(result) + 1n;
  }
  return 1n;
}
const a = randomBetween(10n ** 20n, 10n ** 19n)
const b = randomBetween(10n ** 20n, 10n ** 19n)
aBigInt = a;
bBigInt = b;
aString = a.toString();
bString = b.toString();
aFloat = Number(a);
bFloat = Number(b);
Tests:
  • float multiply

     
    return aFloat * bFloat;
  • bigInt multiply

     
    return aBigInt * bBigInt;
  • float compare

     
    return aFloat === bFloat;
  • bigInt compare

     
    return aBigInt === bBigInt
  • string compare

     
    return aString === bString
  • float greater

     
    return aFloat > bFloat;
  • bigint greater

     
    return aBigInt > bBigInt;
  • string greater

     
    return aString > bString
  • toString bigInt

     
    return aBigInt.toString();
  • toString float

     
    return aFloat.toString();
  • toFloat bigInt

     
    return Number(aBigInt);
  • toFloat string

     
    return parseInt(aString, 10);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    float multiply
    bigInt multiply
    float compare
    bigInt compare
    string compare
    float greater
    bigint greater
    string greater
    toString bigInt
    toString float
    toFloat bigInt
    toFloat string

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 5 days ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Chrome 136 on Windows
View result in a separate tab
Test name Executions per second
float multiply 122942608.0 Ops/sec
bigInt multiply 114065144.0 Ops/sec
float compare 116626992.0 Ops/sec
bigInt compare 122861680.0 Ops/sec
string compare 115880024.0 Ops/sec
float greater 115866088.0 Ops/sec
bigint greater 122146944.0 Ops/sec
string greater 120198248.0 Ops/sec
toString bigInt 15798475.0 Ops/sec
toString float 70153432.0 Ops/sec
toFloat bigInt 26497542.0 Ops/sec
toFloat string 11336580.0 Ops/sec