Created
June 28, 2017 06:41
-
-
Save fohte/52ff2d207bd0d81fd6e0557c2108124d 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 main | |
import ( | |
"fmt" | |
"os" | |
"strconv" | |
"strings" | |
"testing" | |
) | |
var loopnum int = 1000000 | |
func BenchmarkPrint_Join(b *testing.B) { | |
strs := makeDummyStrings(loopnum) | |
b.ResetTimer() | |
fmt.Fprintln(os.Stderr, strings.Join(strs, "\n")) | |
} | |
func BenchmarkPrint_Foreach(b *testing.B) { | |
strs := makeDummyStrings(loopnum) | |
b.ResetTimer() | |
for _, s := range strs { | |
fmt.Fprintln(os.Stderr, s) | |
} | |
} | |
func makeDummyStrings(n int) []string { | |
strs := make([]string, n) | |
for i := 0; i < n; i++ { | |
strs[i] = strconv.Itoa(i) | |
} | |
return strs | |
} |
Author
fohte
commented
Jun 28, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment