HTML Preparation code:
x
 
1
<!--script src="https://raw.githubusercontent.com/iriscouch/bigdecimal.js/v0.6.1/lib/bigdecimal.js"></script-->
2
<script src="https://cdnjs.cloudflare.com/ajax/libs/bignumber.js/9.0.1/bignumber.min.js"></script>
3
<script src="https://cdnjs.cloudflare.com/ajax/libs/big.js/6.0.3/big.min.js"></script>
4
<script src="https://cdnjs.cloudflare.com/ajax/libs/decimal.js/10.2.1/decimal.min.js"></script>
5
<script src="https://unpkg.com/bn.js@5.2.1/lib/bn.js"></script>
6
<!--script src="https://raw.githubusercontent.com/infusion/Fraction.js/v4.0.12/fraction.min.js"></script-->
7
Tests:
  • Native

     
    var a = 57005;
    var b = 42;
    var c = 1.55;
    ((((a + b) * b) / 5) * c).toString();  // "742751.9400000001"
  • Native + toFixed

     
    var a = 57005;
    var b = 42;
    var c = 1.55;
    ((((a + b) * b) / 5) * c).toFixed(9);  // "742751.940000000"
  • decimal.js

     
    var a = new Decimal("57005");
    var b = new Decimal("42");
    var c = 1.55;
    a.plus(b).times(b).dividedBy(5).times(c).toString();  // "742751.94"
  • big.js

     
    var a = new Big("57005");
    var b = new Big("42");
    var c = 1.55;
    a.plus(b).mul(b).div(5).mul(c).toString();  // "742751.94"
  • bignumber.js

     
    var a = new BigNumber("57005");
    var b = new BigNumber("42");
    var c = 1.55;
    a.plus(b).multipliedBy(b).dividedBy(5).multipliedBy(c).toString();  // "742751.94"
  • bn.js

     
    var a = new BN("57005");
    var b = new BN("42");
    var c = 1.55;
    a.add(b).mul(b).divn(5).muln(c).toString();  // "742750"  the divn(5) affects the precision
  • bn.js in-place

     
    var a = new BN("57005");
    var b = new BN("42");
    var c = 1.55;
    a.iadd(b).imul(b).idivn(5).imuln(c).toString();  // "742750"  the idivn(5) affects the precision
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Native
    Native + toFixed
    decimal.js
    big.js
    bignumber.js
    bn.js
    bn.js in-place

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 25 days ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:136.0) Gecko/20100101 Firefox/136.0
Firefox 136 on Windows
View result in a separate tab
Test name Executions per second
Native 1370193920.0 Ops/sec
Native + toFixed 13581755.0 Ops/sec
decimal.js 615282.1 Ops/sec
big.js 326783.9 Ops/sec
bignumber.js 338425.5 Ops/sec
bn.js 1029262.7 Ops/sec
bn.js in-place 1087712.1 Ops/sec