Created
December 30, 2025 04:15
-
-
Save xtaci/ac2f13f0108494d874b25551134e4c9c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "container/list" | |
| "testing" | |
| ) | |
| func BenchmarkLoopSlice(b *testing.B) { | |
| s := make([]byte, b.N) | |
| z := byte(0) | |
| b.ResetTimer() | |
| for i := 0; i < b.N; i++ { | |
| z += s[i] | |
| } | |
| } | |
| func BenchmarkLoopList(b *testing.B) { | |
| l := list.New() | |
| for i := 0; i < b.N; i++ { | |
| l.PushBack(byte(i)) | |
| } | |
| z := byte(0) | |
| b.ResetTimer() | |
| for e := l.Front(); e != nil; e = e.Next() { | |
| z += (e.Value).(byte) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment