Skip to content

Instantly share code, notes, and snippets.

@xtaci
Created December 30, 2025 04:15
Show Gist options
  • Select an option

  • Save xtaci/ac2f13f0108494d874b25551134e4c9c to your computer and use it in GitHub Desktop.

Select an option

Save xtaci/ac2f13f0108494d874b25551134e4c9c to your computer and use it in GitHub Desktop.
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