HTML Preparation code:
AخA
 
1
<script src="https://cdnjs.cloudflare.com/ajax/libs/bignumber.js/9.1.0/bignumber.min.js"></script>
2
<script src="https://cdnjs.cloudflare.com/ajax/libs/big.js/6.2.1/big.min.js"></script>
3
<script src="https://cdnjs.cloudflare.com/ajax/libs/decimal.js/10.3.1/decimal.min.js"></script>
4
<!--<script src="https://cdn.jsdelivr.net/npm/decimal.js-light@2.5.1/decimal.min.js"></script>-->
Script Preparation code:
 
BigNumber.set({
    EXPONENTIAL_AT: 999,
    DECIMAL_PLACES: 18
});
Decimal.set({
    toExpNeg: -999,
    toExpPos: 999,
    precision: 18
});
Big.DP = 18;
Big.NE = -999;
Big.PE = 999;
Tests:
  • Native toString()

     
    {
      const a = Math.random();
      const b = Math.random();
      const c = Math.random();
      const d = Math.random();
      ((a + b) * (c - d));
    }
  • Native toFixed(9)

     
    {
      const a = Math.random();
      const b = Math.random();
      const c = Math.random();
      const d = Math.random();
      ((a + b) * (c - d));
    }
  • bignumber.js toString()

     
    {
      const a = BigNumber(Math.random());
      const b = BigNumber(Math.random());
      const c = BigNumber(Math.random());
      const d = BigNumber(Math.random());
      a.plus(b).times(c.minus(d));
    }
  • bignumber.js toFixed(18)

     
    {
      const a = BigNumber(Math.random());
      const b = BigNumber(Math.random());
      const c = BigNumber(Math.random());
      const d = BigNumber(Math.random());
      a.plus(b).times(c.minus(d));
    }
  • big.js toString()

     
    {
      const a = Big(Math.random());
      const b = Big(Math.random());
      const c = Big(Math.random());
      const d = Big(Math.random());
      a.plus(b).times(c.minus(d));
    }
  • big.js toFixed(18)

     
    {
      const a = Big(Math.random());
      const b = Big(Math.random());
      const c = Big(Math.random());
      const d = Big(Math.random());
      a.plus(b).times(c.minus(d)).toFixed(18);
    }
  • decimal.js toString()

     
    {
      const a = Decimal(Math.random());
      const b = Decimal(Math.random());
      const c = Decimal(Math.random());
      const d = Decimal(Math.random());
      a.plus(b).times(c.minus(d)).toString();
    }
  • decimal.js toFixed(18)

     
    {
      const a = Decimal(Math.random());
      const b = Decimal(Math.random());
      const c = Decimal(Math.random());
      const d = Decimal(Math.random());
      a.plus(b).times(c.minus(d)).toFixed(18);
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Native toString()
    Native toFixed(9)
    bignumber.js toString()
    bignumber.js toFixed(18)
    big.js toString()
    big.js toFixed(18)
    decimal.js toString()
    decimal.js toFixed(18)

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 11 days ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0
Chrome 133 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
Native toString() 40250180.0 Ops/sec
Native toFixed(9) 40400780.0 Ops/sec
bignumber.js toString() 435840.2 Ops/sec
bignumber.js toFixed(18) 438181.8 Ops/sec
big.js toString() 434633.8 Ops/sec
big.js toFixed(18) 379201.7 Ops/sec
decimal.js toString() 353112.1 Ops/sec
decimal.js toFixed(18) 328715.6 Ops/sec