Test name | Executions per second |
---|---|
Native toString() | 2022916.0 Ops/sec |
Native toFixed(9) | 2319269.0 Ops/sec |
bignumber.js toString() | 220101.3 Ops/sec |
bignumber.js toFixed(18) | 201508.3 Ops/sec |
big.js toString() | 230092.5 Ops/sec |
big.js toFixed(18) | 235953.5 Ops/sec |
decimal.js toString() | 190278.5 Ops/sec |
decimal.js toFixed(18) | 175009.4 Ops/sec |
<script src="https://cdnjs.cloudflare.com/ajax/libs/bignumber.js/9.1.0/bignumber.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/big.js/6.2.1/big.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/decimal.js/10.3.1/decimal.min.js"></script>
<!--<script src="https://cdn.jsdelivr.net/npm/decimal.js-light@2.5.1/decimal.min.js"></script>-->
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;
{
const a = Math.random();
const b = Math.random();
const c = Math.random();
const d = Math.random();
((a + b) * (c - d)).toString();
}
{
const a = Math.random();
const b = Math.random();
const c = Math.random();
const d = Math.random();
((a + b) * (c - d)).toFixed(9);
}
{
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)).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)).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)).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)).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)).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)).toFixed(18);
}