Created
December 8, 2016 09:27
-
-
Save yu81/868767bb0fb45a52aabe0c5b188d66c1 to your computer and use it in GitHub Desktop.
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 api | |
import ( | |
"testing" | |
) | |
const iteration = 2 | |
func Benchmark_AppendString1(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
appendString1() | |
} | |
} | |
func Benchmark_AppendString2(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
appendString2() | |
} | |
} | |
func Benchmark_AppendString3(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
appendString3() | |
} | |
} | |
func appendString1() { | |
var list []string | |
for i := 0; i < iteration; i++ { | |
list = append(list, "foo") | |
} | |
} | |
func appendString2() { | |
list := make([]string, 0, iteration) | |
for i := 0; i < iteration; i++ { | |
list = append(list, "foo") | |
} | |
} | |
func appendString3() { | |
list := make([]string, iteration) | |
for i := 0; i < iteration; i++ { | |
list[i] = "foo" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment