Skip to content

optimize further WriteToSlice with len<32#213

Merged
holiman merged 1 commit intoholiman:masterfrom
MichaelMure:master
Feb 28, 2026
Merged

optimize further WriteToSlice with len<32#213
holiman merged 1 commit intoholiman:masterfrom
MichaelMure:master

Conversation

@MichaelMure
Copy link
Contributor

It may or may not make sense, I just did it out of fun after looking at #212

goarch: amd64
pkg: github.com/holiman/uint256
cpu: AMD Ryzen 5 3600 6-Core Processor
                    │   old.txt    │               new.txt                │
                    │    sec/op    │    sec/op     vs base                │
WriteTo/fixed-20-12   0.7865n ± 1%   0.7819n ± 4%        ~ (p=0.089 n=10)
WriteTo/fixed-32-12    1.049n ± 0%    1.035n ± 3%        ~ (p=0.062 n=10)
WriteTo/slice-12       2.587n ± 2%    2.321n ± 1%  -10.26% (p=0.000 n=10)
WriteTo/put256-12      1.038n ± 5%    1.048n ± 0%        ~ (p=0.196 n=10)
geomean                1.220n         1.184n        -2.91%

                    │   old.txt    │              new.txt                │
                    │     B/op     │    B/op     vs base                 │
WriteTo/fixed-20-12   0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
WriteTo/fixed-32-12   0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
WriteTo/slice-12      0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
WriteTo/put256-12     0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
geomean                          ²               +0.00%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

                    │   old.txt    │              new.txt                │
                    │  allocs/op   │ allocs/op   vs base                 │
WriteTo/fixed-20-12   0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
WriteTo/fixed-32-12   0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
WriteTo/slice-12      0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
WriteTo/put256-12     0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
geomean                          ²               +0.00%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

goos: linux
goarch: amd64
pkg: github.com/holiman/uint256
cpu: AMD Ryzen 5 3600 6-Core Processor
                    │   old.txt    │               new.txt                │
                    │    sec/op    │    sec/op     vs base                │
WriteTo/fixed-20-12   0.7865n ± 1%   0.7819n ± 4%        ~ (p=0.089 n=10)
WriteTo/fixed-32-12    1.049n ± 0%    1.035n ± 3%        ~ (p=0.062 n=10)
WriteTo/slice-12       2.587n ± 2%    2.321n ± 1%  -10.26% (p=0.000 n=10)
WriteTo/put256-12      1.038n ± 5%    1.048n ± 0%        ~ (p=0.196 n=10)
geomean                1.220n         1.184n        -2.91%

                    │   old.txt    │              new.txt                │
                    │     B/op     │    B/op     vs base                 │
WriteTo/fixed-20-12   0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
WriteTo/fixed-32-12   0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
WriteTo/slice-12      0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
WriteTo/put256-12     0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
geomean                          ²               +0.00%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

                    │   old.txt    │              new.txt                │
                    │  allocs/op   │ allocs/op   vs base                 │
WriteTo/fixed-20-12   0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
WriteTo/fixed-32-12   0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
WriteTo/slice-12      0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
WriteTo/put256-12     0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
geomean                          ²               +0.00%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean
Copy link
Owner

@holiman holiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@holiman holiman merged commit 217c778 into holiman:master Feb 28, 2026
8 checks passed
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