Skip to content

Instantly share code, notes, and snippets.

@dtjm
Last active April 18, 2016 16:34
Show Gist options
  • Select an option

  • Save dtjm/d232bf2ddb56d9e1349ca627450dba02 to your computer and use it in GitHub Desktop.

Select an option

Save dtjm/d232bf2ddb56d9e1349ca627450dba02 to your computer and use it in GitHub Desktop.

Revisions

  1. Sam Nguyen revised this gist Apr 18, 2016. 2 changed files with 4 additions and 4 deletions.
    2 changes: 1 addition & 1 deletion map_test.go
    Original file line number Diff line number Diff line change
    @@ -23,8 +23,8 @@ func BenchmarkMapBytesKey(b *testing.B) {
    func BenchmarkMapBytesConvertKey(b *testing.B) {
    var m map[string]string = make(map[string]string)
    var k []byte = []byte("key")
    var ks = string(k)
    for i := 0; i < b.N; i++ {
    var ks = string(k)
    _, _ = m[ks]
    }
    }
    6 changes: 3 additions & 3 deletions results.txt
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    $ go test -bench=. -benchmem map_test.go
    testing: warning: no tests to run
    PASS
    BenchmarkMapStringKey-4 300000000 4.88 ns/op 0 B/op 0 allocs/op
    BenchmarkMapStringKey-4 300000000 4.57 ns/op 0 B/op 0 allocs/op
    BenchmarkMapBytesKey-4 200000000 7.00 ns/op 0 B/op 0 allocs/op
    BenchmarkMapBytesConvertKey-4 300000000 4.59 ns/op 0 B/op 0 allocs/op
    ok command-line-arguments 9.924s
    BenchmarkMapBytesConvertKey-4 100000000 20.8 ns/op 0 B/op 0 allocs/op
    ok command-line-arguments 13.046s
  2. Sam Nguyen revised this gist Apr 18, 2016. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions results.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    $ go test -bench=. -benchmem map_test.go
    testing: warning: no tests to run
    PASS
    BenchmarkMapStringKey-4 300000000 4.88 ns/op 0 B/op 0 allocs/op
    BenchmarkMapBytesKey-4 200000000 7.00 ns/op 0 B/op 0 allocs/op
    BenchmarkMapBytesConvertKey-4 300000000 4.59 ns/op 0 B/op 0 allocs/op
    ok command-line-arguments 9.924s
  3. Sam Nguyen created this gist Apr 18, 2016.
    30 changes: 30 additions & 0 deletions map_test.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    package map_test

    import (
    "testing"
    )

    func BenchmarkMapStringKey(b *testing.B) {
    var m map[string]string = make(map[string]string)
    var k string = "key"
    for i := 0; i < b.N; i++ {
    _, _ = m[k]
    }
    }

    func BenchmarkMapBytesKey(b *testing.B) {
    var m map[string]string = make(map[string]string)
    var k []byte = []byte("key")
    for i := 0; i < b.N; i++ {
    _, _ = m[string(k)]
    }
    }

    func BenchmarkMapBytesConvertKey(b *testing.B) {
    var m map[string]string = make(map[string]string)
    var k []byte = []byte("key")
    var ks = string(k)
    for i := 0; i < b.N; i++ {
    _, _ = m[ks]
    }
    }