<script src='https://cdn.jsdelivr.net/npm/decimal.js-light@2.5.1/decimal.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/big.js@6.1.1/big.js'></script>
var x = 5.236;
Decimal('0.00253452345').times(x)
Decimal('0.00253452345').plus(x)
Decimal('0.00253452345').minus(x)
Decimal('0.00253452345').div(x)
Decimal('0.00253452345').times(Decimal('5.236').minus('1.111')).div('4.55').plus('44.44')
Big('0.00253452345').times(x)
Big('0.00253452345').plus(x)
Big('0.00253452345').minus(x)
Big('0.00253452345').div(x)
Big('0.00253452345').times(Big('5.236').minus('1.111')).div('4.55').plus('44.44')
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Decimal times | |
Decimal plus | |
Decimal minus | |
Decimal div | |
Decimal times minus div plus | |
Big times | |
Big plus | |
Big minus | |
Big div | |
Big times minus div plus |
Test name | Executions per second |
---|---|
Decimal times | 745186.7 Ops/sec |
Decimal plus | 773281.2 Ops/sec |
Decimal minus | 746528.4 Ops/sec |
Decimal div | 301540.2 Ops/sec |
Decimal times minus div plus | 167428.4 Ops/sec |
Big times | 657581.8 Ops/sec |
Big plus | 829702.6 Ops/sec |
Big minus | 741406.8 Ops/sec |
Big div | 180024.1 Ops/sec |
Big times minus div plus | 118451.4 Ops/sec |
Let's break down the benchmark and explain what's being tested.
What is being tested:
The benchmark tests the performance of two libraries:
Both libraries are used for decimal arithmetic, which can be useful in various applications such as finance, science, and engineering.
Options compared:
The benchmark compares the performance of each library when performing different arithmetic operations on decimal numbers:
plus
)minus
)times
)div
)Additionally, some test cases also involve more complex expressions involving multiple libraries' functions, such as:
Decimal('0.00253452345').times(x) + '44.44'
Big('0.00253452345').times(Big('5.236').minus('1.111')).div('4.55')
Pros and cons of each approach:
Decimal.js:
Pros:
Cons:
Big.js:
Pros:
Cons:
Other considerations:
x
as the multiplier, which may not accurately represent real-world scenarios where the input values can vary greatly.Special JS feature or syntax:
There are no special JS features or syntax used in this benchmark that would affect its performance or execution.