Created
July 28, 2017 06:33
-
-
Save timakin/dbeaf2bdbd37bc8c20aabac6d9fab535 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 | |
func main() { | |
PopWithCopy() | |
} | |
func PopWithCopy() string { | |
strs := []string{ | |
"AAAAAAAAAAA", | |
"AAAAAAAAAAA", | |
"AAAAAAAAAAA", | |
"AAAAAAAAAAA", | |
"AAAAAAAAAAA", | |
"AAAAAAAAAAA", | |
"AAAAAAAAAAA", | |
"AAAAAAAAAAA", | |
"AAAAAAAAAAA", | |
"AAAAAAAAAAA", | |
} | |
p := strs[0] | |
copy(strs, strs[1:]) | |
return p | |
} | |
func PopWithEqual() string { | |
strs := []string{ | |
"AAAAAAAAAAA", | |
"AAAAAAAAAAA", | |
"AAAAAAAAAAA", | |
"AAAAAAAAAAA", | |
"AAAAAAAAAAA", | |
"AAAAAAAAAAA", | |
"AAAAAAAAAAA", | |
"AAAAAAAAAAA", | |
"AAAAAAAAAAA", | |
"AAAAAAAAAAA", | |
} | |
p, strs := strs[0], strs[1:] | |
return p | |
} | |
package main | |
import ( | |
"testing" | |
) | |
func Benchmark_NormalPop(b *testing.B) { | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
PopWithCopy() | |
} | |
} | |
func Benchmark_EqualPop(b *testing.B) { | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
PopWithEqual() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment