<script src='https://cdn.jsdelivr.net/npm/decimal.js-light@2.5.0/decimal.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/exact-math@2.2.3/dist/exact-math.js'></script>
var x = 5.236;
Decimal('0.00253452345').times(x)
0.00253452345 * x
exactMath.div('0.00253452345', x);
Decimal('0.00253452345').plus(x)
exactMath.add('0.00253452345', x);
Decimal('0.00253452345').times(x)
exactMath.mul('0.00253452345', x);
exactMath.formula('0.00253452345*(5.236-1.111)/4.55');
Decimal('0.00253452345').times(Decimal('5.236').minus('1.111')).div('4.55')
Decimal('0.00253452345').div(x)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Multiply using Decimal.js | |
Multiply using native numbers | |
exactMath div | |
Decimal plus | |
exactMath add | |
Decimal times | |
exactMath mul | |
exactMath formula | |
Decimal times minus div | |
Decimal div |
Test name | Executions per second |
---|---|
Multiply using Decimal.js | 994204.1 Ops/sec |
Multiply using native numbers | 14774614.0 Ops/sec |
exactMath div | 32990.6 Ops/sec |
Decimal plus | 1020175.6 Ops/sec |
exactMath add | 305080.3 Ops/sec |
Decimal times | 1002935.7 Ops/sec |
exactMath mul | 206247.9 Ops/sec |
exactMath formula | 10830.2 Ops/sec |
Decimal times minus div | 328676.6 Ops/sec |
Decimal div | 479168.3 Ops/sec |
Let's break down the benchmark and its various options.
Benchmark Overview The benchmark compares the performance of three approaches to perform mathematical operations on decimal numbers:
Options Compared The benchmark compares the performance of each approach in performing various mathematical operations, including:
times
or mul
)plus
or add
)div
)formula
)minus
)Pros and Cons of Each Approach
Performance Results The benchmark results show that:
In general, the benchmark suggests that: