Created
January 27, 2021 16:20
-
-
Save robert-zaremba/ea195543ec913186d80c305e84e38fac to your computer and use it in GitHub Desktop.
Go: benchmark len
This file contains 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 pkg | |
import "testing" | |
var a []int | |
var N = 200000000 | |
func init() { | |
l := 10000 | |
a = make([]int, l, l) | |
} | |
func BenchmarkLen1(b *testing.B) { | |
x := 0 | |
for i := 0; i < N; i++ { | |
x += len(a) | |
} | |
println(x) | |
} | |
func BenchmarkLen2(b *testing.B) { | |
l := len(a) | |
x := 0 | |
for i := 0; i < N; i++ { | |
x += l | |
} | |
println(x) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result: