Skip to content

Instantly share code, notes, and snippets.

@thiagocaiubi
Forked from dtjm/join_test.go
Created January 24, 2018 15:42
Show Gist options
  • Save thiagocaiubi/77c363cd2f28d1dc91d7a699d3452d2f to your computer and use it in GitHub Desktop.
Save thiagocaiubi/77c363cd2f28d1dc91d7a699d3452d2f to your computer and use it in GitHub Desktop.

Revisions

  1. Sam Nguyen created this gist May 18, 2015.
    32 changes: 32 additions & 0 deletions join_test.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    package join

    import (
    "fmt"
    "strings"
    "testing"
    )

    var (
    testData = []string{"a", "b", "c", "d", "e"}
    )

    func BenchmarkJoin(b *testing.B) {
    for i := 0; i < b.N; i++ {
    s := strings.Join(testData, ":")
    _ = s
    }
    }

    func BenchmarkSprintf(b *testing.B) {
    for i := 0; i < b.N; i++ {
    s := fmt.Sprintf("%s:%s:%s:%s:%s", testData[0], testData[1], testData[2], testData[3], testData[4])
    _ = s
    }
    }

    func BenchmarkConcat(b *testing.B) {
    for i := 0; i < b.N; i++ {
    s := testData[0] + ":" + testData[1] + ":" + testData[2] + ":" + testData[3] + ":" + testData[4]
    _ = s
    }
    }