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

performance opt: using copy instead of append #38

Merged
merged 1 commit into from
Mar 6, 2022
Merged

performance opt: using copy instead of append #38

merged 1 commit into from
Mar 6, 2022

Conversation

wathenjiang
Copy link
Contributor

Please see https://gist.github.com/spongecaptain/c5eedde03caaaa5f3de0331a50d24baa

Using copy instead of append brings performance improvements.

Original version benchmark test result:

$ go test -v -run=none -bench=. -cpu 1,2,4,8,16 -benchmem

goos: darwin
goarch: arm64
pkg: github.com/embano1/memlog
BenchmarkLog_write
BenchmarkLog_write              12658945                83.79 ns/op           89 B/op          1 allocs/op
BenchmarkLog_write-2            14599183                81.88 ns/op           89 B/op          1 allocs/op
BenchmarkLog_write-4            14565168                81.85 ns/op           89 B/op          1 allocs/op
BenchmarkLog_write-8            14652230                80.89 ns/op           89 B/op          1 allocs/op
BenchmarkLog_write-16           14582964                81.61 ns/op           89 B/op          1 allocs/op
BenchmarkLog_read
BenchmarkLog_read               23078679                51.61 ns/op           32 B/op          1 allocs/op
BenchmarkLog_read-2             23851464                49.38 ns/op           32 B/op          1 allocs/op
BenchmarkLog_read-4             23998719                50.11 ns/op           32 B/op          1 allocs/op
BenchmarkLog_read-8             23799724                50.11 ns/op           32 B/op          1 allocs/op
BenchmarkLog_read-16            23617048                49.77 ns/op           32 B/op          1 allocs/op
PASS
ok      github.com/embano1/memlog       12.563s

Using copy version:

$ go test -v -run=none -bench=. -cpu 1,2,4,8,16 -benchmem

goos: darwin
goarch: arm64
pkg: github.com/embano1/memlog
BenchmarkLog_write
BenchmarkLog_write              15381063                78.47 ns/op           89 B/op          1 allocs/op
BenchmarkLog_write-2            15534843                77.78 ns/op           89 B/op          1 allocs/op
BenchmarkLog_write-4            15860680                75.88 ns/op           89 B/op          1 allocs/op
BenchmarkLog_write-8            15975698                75.16 ns/op           89 B/op          1 allocs/op
BenchmarkLog_write-16           15493441                76.15 ns/op           89 B/op          1 allocs/op
BenchmarkLog_read
BenchmarkLog_read               25497036                47.53 ns/op           32 B/op          1 allocs/op
BenchmarkLog_read-2             26456144                45.67 ns/op           32 B/op          1 allocs/op
BenchmarkLog_read-4             25824014                45.50 ns/op           32 B/op          1 allocs/op
BenchmarkLog_read-8             26311268                45.73 ns/op           32 B/op          1 allocs/op
BenchmarkLog_read-16            26083293                45.62 ns/op           32 B/op          1 allocs/op
PASS
ok      github.com/embano1/memlog       13.762s

@codecov-commenter
Copy link

codecov-commenter commented Mar 5, 2022

Codecov Report

Merging #38 (5fd6552) into main (d374463) will increase coverage by 0.09%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #38      +/-   ##
==========================================
+ Coverage   87.21%   87.31%   +0.09%     
==========================================
  Files           7        7              
  Lines         266      268       +2     
==========================================
+ Hits          232      234       +2     
  Misses         19       19              
  Partials       15       15              
Impacted Files Coverage Δ
memlog.go 85.18% <100.00%> (+0.27%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d374463...5fd6552. Read the comment docs.

Copy link
Owner

@embano1 embano1 left a comment

Choose a reason for hiding this comment

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

You're the best! Thx a ton and keep em coming :)

@embano1 embano1 enabled auto-merge March 6, 2022 07:22
@embano1 embano1 disabled auto-merge March 6, 2022 07:23
@embano1 embano1 merged commit dfaa93d into embano1:main Mar 6, 2022
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.

3 participants