decimal
decimal copied to clipboard
Speedup pow_of_ten/1
This PR speedups decimal:add/2 and few other functions with usage of case expression for pow_of_ten calculations for exponents up to 100 (should be enough for most real-world cases).
How to test:
- checkout a commit with a bench (e386e10e16255bfa9f717ffe36210b5171d06c1a)
- create a baseline with
rebar3 bench --save-baseline upstream
- checkout a commit with an optimization (41b0ee87d942952fb309a6580eb6bb01ce7dba94)
- bench and compare with
rebar3 bench --baseline upstream
My results for OTP 26:
===> Testing bench_decimal:bench_add()
===> Stats for wall_time
Min: 15.27μs (- 5394.00ns / 26.1%)
25 percentile: 15.49μs (- 5533.00ns / 26.3%)
Median: 15.62μs (- 5588.00ns / 26.3%)
75 percentile: 15.73μs (- 5635.00ns / 26.4%)
Max: 15.91μs (- 7458.00ns / 31.9%)
Outliers: Lo: 0; Hi: 0; Sum: 0
Outlier variance: 9.90000e-3 (unaffected)
> Bootstrapped
Mean: 15.62μs (- 5603.00ns / 26.4%)
Std deviation: 163.00ns
> Relative
Difference at 95.0 confidence
-5603.00ns ± 74.00ns
-26.40% ± 0.35%
(Student's t, pooled s = 268.668)
and OTP 24:
===> Testing bench_decimal:bench_add()
===> Stats for wall_time
Min: 16.24μs (- 5275.00ns / 24.5%)
25 percentile: 16.50μs (- 5897.00ns / 26.3%)
Median: 16.67μs (- 5921.00ns / 26.2%)
75 percentile: 16.90μs (- 5844.00ns / 25.7%)
Max: 17.08μs (- 6121.00ns / 26.4%)
Outliers: Lo: 0; Hi: 0; Sum: 0
Outlier variance: 6.60675e-2 (slight)
> Bootstrapped
Mean: 16.69μs (- 5815.00ns / 25.8%)
Std deviation: 233.00ns
> Relative
Difference at 95.0 confidence
-5815.00ns ± 83.00ns
-25.84% ± 0.37%
(Student's t, pooled s = 300.593)