Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizations 2 #64

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

anatoly-kussul
Copy link
Contributor

@anatoly-kussul anatoly-kussul commented Jan 9, 2025

At this point I was just curious about how much further I can push it.
Feel free to close this PR if you feel like this is too much.

bench vs 4.2.0:

goos: linux
goarch: amd64
pkg: github.com/lithammer/shortuuid/v4
cpu: 12th Gen Intel(R) Core(TM) i5-12400F
                         │   v4.2.0    │                new2                 │
                         │   sec/op    │   sec/op     vs base                │
UUID-12                    123.3n ± 0%   101.5n ± 1%  -17.67% (p=0.000 n=10)
Encoding-12                44.42n ± 1%   30.43n ± 1%  -31.50% (p=0.000 n=10)
EncodingB57_MB-12          123.2n ± 4%   135.3n ± 1%   +9.91% (p=0.000 n=10)
EncodingB16-12             134.5n ± 0%   119.1n ± 0%  -11.42% (p=0.000 n=10)
EncodingB16_MB-12          327.0n ± 1%   189.4n ± 1%  -42.08% (p=0.000 n=10)
Decoding-12                173.9n ± 1%   164.4n ± 1%   -5.49% (p=0.000 n=10)
DecodingB16-12             206.0n ± 1%   193.6n ± 1%   -6.02% (p=0.000 n=10)
DecodingB16_MB-12          254.6n ± 1%   247.0n ± 2%   -3.00% (p=0.000 n=10)
NewWithAlphabet-12         387.2n ± 1%   383.8n ± 1%   -0.90% (p=0.024 n=10)
NewWithAlphabetB16-12      270.4n ± 1%   233.1n ± 0%  -13.83% (p=0.000 n=10)
NewWithAlphabetB16_MB-12   553.5n ± 0%   399.2n ± 1%  -27.88% (p=0.000 n=10)
NewWithNamespace-12        249.3n ± 1%   149.6n ± 1%  -40.00% (p=0.000 n=10)
NewWithNamespaceHttp-12    255.1n ± 3%   152.8n ± 1%  -40.11% (p=0.000 n=10)
NewWithNamespaceHttps-12   256.4n ± 2%   153.8n ± 1%  -40.04% (p=0.000 n=10)
geomean                    206.5n        162.9n       -21.08%

                         │    v4.2.0     │                 new2                 │
                         │     B/op      │    B/op     vs base                  │
UUID-12                     24.00 ± 0%     24.00 ± 0%        ~ (p=1.000 n=10) ¹
Encoding-12                 24.00 ± 0%     24.00 ± 0%        ~ (p=1.000 n=10) ¹
EncodingB57_MB-12           72.00 ± 0%     80.00 ± 0%  +11.11% (p=0.000 n=10)
EncodingB16-12              64.00 ± 0%     32.00 ± 0%  -50.00% (p=0.000 n=10)
EncodingB16_MB-12          480.00 ± 0%     96.00 ± 0%  -80.00% (p=0.000 n=10)
Decoding-12                 0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=10) ¹
DecodingB16-12              0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=10) ¹
DecodingB16_MB-12           0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=10) ¹
NewWithAlphabet-12          264.0 ± 0%     264.0 ± 0%        ~ (p=1.000 n=10) ¹
NewWithAlphabetB16-12      128.00 ± 0%     96.00 ± 0%  -25.00% (p=0.000 n=10)
NewWithAlphabetB16_MB-12    544.0 ± 0%     160.0 ± 0%  -70.59% (p=0.000 n=10)
NewWithNamespace-12        200.00 ± 0%     24.00 ± 0%  -88.00% (p=0.000 n=10)
NewWithNamespaceHttp-12    208.00 ± 0%     24.00 ± 0%  -88.46% (p=0.000 n=10)
NewWithNamespaceHttps-12   224.00 ± 0%     24.00 ± 0%  -89.29% (p=0.000 n=10)
geomean                                ²               -51.82%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

                         │    v4.2.0    │                 new2                 │
                         │  allocs/op   │ allocs/op   vs base                  │
UUID-12                    1.000 ± 0%     1.000 ± 0%        ~ (p=1.000 n=10) ¹
Encoding-12                1.000 ± 0%     1.000 ± 0%        ~ (p=1.000 n=10) ¹
EncodingB57_MB-12          2.000 ± 0%     1.000 ± 0%  -50.00% (p=0.000 n=10)
EncodingB16-12             2.000 ± 0%     1.000 ± 0%  -50.00% (p=0.000 n=10)
EncodingB16_MB-12          4.000 ± 0%     1.000 ± 0%  -75.00% (p=0.000 n=10)
Decoding-12                0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=10) ¹
DecodingB16-12             0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=10) ¹
DecodingB16_MB-12          0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=10) ¹
NewWithAlphabet-12         2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
NewWithAlphabetB16-12      3.000 ± 0%     2.000 ± 0%  -33.33% (p=0.000 n=10)
NewWithAlphabetB16_MB-12   5.000 ± 0%     2.000 ± 0%  -60.00% (p=0.000 n=10)
NewWithNamespace-12        5.000 ± 0%     1.000 ± 0%  -80.00% (p=0.000 n=10)
NewWithNamespaceHttp-12    5.000 ± 0%     1.000 ± 0%  -80.00% (p=0.000 n=10)
NewWithNamespaceHttps-12   5.000 ± 0%     1.000 ± 0%  -80.00% (p=0.000 n=10)
geomean                               ²               -47.13%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

bench vs #63

goos: linux
goarch: amd64
pkg: github.com/lithammer/shortuuid/v4
cpu: 12th Gen Intel(R) Core(TM) i5-12400F
                         │     new     │                new2                 │
                         │   sec/op    │   sec/op     vs base                │
UUID-12                    119.6n ± 0%   101.5n ± 1%  -15.09% (p=0.000 n=10)
Encoding-12                42.32n ± 0%   30.43n ± 1%  -28.10% (p=0.000 n=10)
EncodingB57_MB-12          116.5n ± 2%   135.3n ± 1%  +16.13% (p=0.000 n=10)
EncodingB16-12             151.9n ± 0%   119.1n ± 0%  -21.59% (p=0.000 n=10)
EncodingB16_MB-12          191.2n ± 2%   189.4n ± 1%        ~ (p=0.469 n=10)
Decoding-12                167.4n ± 1%   164.4n ± 1%   -1.76% (p=0.000 n=10)
DecodingB16-12             200.0n ± 1%   193.6n ± 1%   -3.20% (p=0.000 n=10)
DecodingB16_MB-12          249.9n ± 2%   247.0n ± 2%   -1.16% (p=0.001 n=10)
NewWithAlphabet-12         381.0n ± 2%   383.8n ± 1%        ~ (p=0.110 n=10)
NewWithAlphabetB16-12      293.6n ± 1%   233.1n ± 0%  -20.62% (p=0.000 n=10)
NewWithAlphabetB16_MB-12   403.5n ± 1%   399.2n ± 1%   -1.07% (p=0.003 n=10)
NewWithNamespace-12        166.3n ± 1%   149.6n ± 1%  -10.07% (p=0.000 n=10)
NewWithNamespaceHttp-12    169.8n ± 1%   152.8n ± 1%  -10.04% (p=0.000 n=10)
NewWithNamespaceHttps-12   167.4n ± 1%   153.8n ± 1%   -8.13% (p=0.000 n=10)
geomean                    177.4n        162.9n        -8.15%

                         │     new      │                new2                 │
                         │     B/op     │    B/op     vs base                 │
UUID-12                    24.00 ± 0%     24.00 ± 0%       ~ (p=1.000 n=10) ¹
Encoding-12                24.00 ± 0%     24.00 ± 0%       ~ (p=1.000 n=10) ¹
EncodingB57_MB-12          80.00 ± 0%     80.00 ± 0%       ~ (p=1.000 n=10) ¹
EncodingB16-12             32.00 ± 0%     32.00 ± 0%       ~ (p=1.000 n=10) ¹
EncodingB16_MB-12          96.00 ± 0%     96.00 ± 0%       ~ (p=1.000 n=10) ¹
Decoding-12                0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
DecodingB16-12             0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
DecodingB16_MB-12          0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
NewWithAlphabet-12         264.0 ± 0%     264.0 ± 0%       ~ (p=1.000 n=10) ¹
NewWithAlphabetB16-12      96.00 ± 0%     96.00 ± 0%       ~ (p=1.000 n=10) ¹
NewWithAlphabetB16_MB-12   160.0 ± 0%     160.0 ± 0%       ~ (p=1.000 n=10) ¹
NewWithNamespace-12        24.00 ± 0%     24.00 ± 0%       ~ (p=1.000 n=10) ¹
NewWithNamespaceHttp-12    24.00 ± 0%     24.00 ± 0%       ~ (p=1.000 n=10) ¹
NewWithNamespaceHttps-12   24.00 ± 0%     24.00 ± 0%       ~ (p=1.000 n=10) ¹
geomean                               ²               +0.00%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

                         │     new      │                new2                 │
                         │  allocs/op   │ allocs/op   vs base                 │
UUID-12                    1.000 ± 0%     1.000 ± 0%       ~ (p=1.000 n=10) ¹
Encoding-12                1.000 ± 0%     1.000 ± 0%       ~ (p=1.000 n=10) ¹
EncodingB57_MB-12          1.000 ± 0%     1.000 ± 0%       ~ (p=1.000 n=10) ¹
EncodingB16-12             1.000 ± 0%     1.000 ± 0%       ~ (p=1.000 n=10) ¹
EncodingB16_MB-12          1.000 ± 0%     1.000 ± 0%       ~ (p=1.000 n=10) ¹
Decoding-12                0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
DecodingB16-12             0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
DecodingB16_MB-12          0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
NewWithAlphabet-12         2.000 ± 0%     2.000 ± 0%       ~ (p=1.000 n=10) ¹
NewWithAlphabetB16-12      2.000 ± 0%     2.000 ± 0%       ~ (p=1.000 n=10) ¹
NewWithAlphabetB16_MB-12   2.000 ± 0%     2.000 ± 0%       ~ (p=1.000 n=10) ¹
NewWithNamespace-12        1.000 ± 0%     1.000 ± 0%       ~ (p=1.000 n=10) ¹
NewWithNamespaceHttp-12    1.000 ± 0%     1.000 ± 0%       ~ (p=1.000 n=10) ¹
NewWithNamespaceHttps-12   1.000 ± 0%     1.000 ± 0%       ~ (p=1.000 n=10) ¹
geomean                               ²               +0.00%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

@lithammer lithammer self-requested a review January 9, 2025 07:44
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.

1 participant