Created
June 24, 2020 05:02
-
-
Save ken39arg/7c0edba919df00230fc58f433c2cec52 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 ( | |
| "fmt" | |
| "strconv" | |
| "testing" | |
| ) | |
| var columns = []string{"a", "b", "c", "d", "e", "f"} | |
| func Benchmark_AddStr(b *testing.B) { | |
| b.ResetTimer() | |
| for i := 0; i < b.N; i++ { | |
| nc := make([]string, len(columns)) | |
| for j, c := range columns { | |
| nc[j] = "c." + c | |
| } | |
| } | |
| } | |
| func Benchmark_SprintfStr(b *testing.B) { | |
| b.ResetTimer() | |
| for i := 0; i < b.N; i++ { | |
| nc := make([]string, len(columns)) | |
| for j, c := range columns { | |
| nc[j] = fmt.Sprintf("c.%s", c) | |
| } | |
| } | |
| } | |
| func Benchmark_AddInt(b *testing.B) { | |
| b.ResetTimer() | |
| for i := 0; i < b.N; i++ { | |
| nc := make([]string, len(columns)) | |
| for j := range columns { | |
| nc[j] = "c." + strconv.Itoa(j) | |
| } | |
| } | |
| } | |
| func Benchmark_SprintfInt(b *testing.B) { | |
| b.ResetTimer() | |
| for i := 0; i < b.N; i++ { | |
| nc := make([]string, len(columns)) | |
| for j := range columns { | |
| nc[j] = fmt.Sprintf("c.%d", j) | |
| } | |
| } | |
| } |
ken39arg
commented
Jun 24, 2020
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment