Skip to content

Conversation

@quagmt
Copy link
Owner

@quagmt quagmt commented Nov 1, 2024

Description

  • Optimize String with table lookup method
  • Remove byte pre-allocation because it's likely to be optimized by the compiler anyways
  • Benchmark before and after
goos: linux
goarch: amd64
pkg: github.com/quagmt/udecimal/benchmarks
cpu: Intel(R) Core(TM) i9-14900HX
                                                       │     old      │               udecimal               │
                                                       │    sec/op    │    sec/op     vs base                │
String/udec/1234567890123456789.1234567890123456879-32   88.52n ±  6%   77.35n ± 10%  -12.61% (p=0.000 n=10)
String/udec/123-32                                       15.54n ± 10%   14.22n ±  4%   -8.52% (p=0.000 n=10)
String/udec/123456.123456-32                             35.95n ±  5%   31.49n ± 11%  -12.41% (p=0.000 n=10)
String/udec/1234567890-32                                33.29n ±  8%   30.60n ±  8%   -8.09% (p=0.009 n=10)
String/udec/0.1234567890123456879-32                     48.91n ±  8%   42.60n ±  6%  -12.91% (p=0.000 n=10)
String/udec/12345.1234567890123456789-32                 61.08n ±  5%   51.02n ±  8%  -16.47% (p=0.000 n=10)
geomean                                                  41.24n         36.34n        -11.88%

                                                       │    old     │               udecimal               │
                                                       │    B/op    │    B/op     vs base                  │
String/udec/1234567890123456789.1234567890123456879-32   48.00 ± 0%   48.00 ± 0%        ~ (p=1.000 n=10) ¹
String/udec/123-32                                       5.000 ± 0%   3.000 ± 0%  -40.00% (p=0.000 n=10)
String/udec/123456.123456-32                             16.00 ± 0%   16.00 ± 0%        ~ (p=1.000 n=10) ¹
String/udec/1234567890-32                                16.00 ± 0%   16.00 ± 0%        ~ (p=1.000 n=10) ¹
String/udec/0.1234567890123456879-32                     24.00 ± 0%   24.00 ± 0%        ~ (p=1.000 n=10) ¹
String/udec/12345.1234567890123456789-32                 32.00 ± 0%   32.00 ± 0%        ~ (p=1.000 n=10) ¹
geomean                                                  19.01        17.46        -8.16%
¹ all samples are equal

                                                       │    old     │              udecimal               │
                                                       │ allocs/op  │ allocs/op   vs base                 │
String/udec/1234567890123456789.1234567890123456879-32   1.000 ± 0%   1.000 ± 0%       ~ (p=1.000 n=10) ¹
String/udec/123-32                                       1.000 ± 0%   1.000 ± 0%       ~ (p=1.000 n=10) ¹
String/udec/123456.123456-32                             1.000 ± 0%   1.000 ± 0%       ~ (p=1.000 n=10) ¹
String/udec/1234567890-32                                1.000 ± 0%   1.000 ± 0%       ~ (p=1.000 n=10) ¹
String/udec/0.1234567890123456879-32                     1.000 ± 0%   1.000 ± 0%       ~ (p=1.000 n=10) ¹
String/udec/12345.1234567890123456789-32                 1.000 ± 0%   1.000 ± 0%       ~ (p=1.000 n=10) ¹
geomean                                                  1.000        1.000       +0.00%
¹ all samples are equal

@codecov
Copy link

codecov bot commented Nov 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.79%. Comparing base (1d8c752) to head (f14245b).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #19      +/-   ##
==========================================
+ Coverage   95.74%   95.79%   +0.04%     
==========================================
  Files           5        5              
  Lines        1693     1711      +18     
==========================================
+ Hits         1621     1639      +18     
  Misses         48       48              
  Partials       24       24              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@quagmt quagmt merged commit 4ea866a into master Nov 1, 2024
9 checks passed
@quagmt quagmt deleted the feat/improve-string branch November 1, 2024 04:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants