Created
August 21, 2023 04:15
-
-
Save kwilczynski/f2be077bafaea3aa1ae024020c0962c5 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 ( | |
"testing" | |
) | |
func A() { | |
m := map[int][]string{} | |
for i, _ := range []int{1, 2, 3} { | |
var x []string | |
for _, c := range []string{"a", "b", "c"} { | |
x = append(x, c) | |
} | |
m[i] = x | |
} | |
} | |
func B() { | |
m := map[int][]string{} | |
var x []string | |
for i, _ := range []int{1, 2, 3} { | |
for _, c := range []string{"a", "b", "c"} { | |
x = append(x, c) | |
} | |
m[i] = x | |
x = nil | |
} | |
} | |
func BenchmarkA(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
A() | |
} | |
} | |
func BenchmarkB(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
B() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For me, on 64-bit Linux, "A" tends to run slightly faster (not that there is any real-life difference here), most of the time (note: this does not mean always).