Created
September 18, 2019 13:29
-
-
Save jarifibrahim/bf505d055f01520f4838866523df8f7f to your computer and use it in GitHub Desktop.
Benchmark interface
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
type foo interface { | |
increment() | |
} | |
type X struct { | |
i int | |
} | |
func (x *X) increment() { | |
x.i++ | |
} | |
func BenchmarkInterface(b *testing.B) { | |
var a foo = new(X) | |
for i := 0; i < b.N; i++ { | |
a.increment() | |
} | |
} | |
func BenchmarkConcreteType(b *testing.B) { | |
var a = new(X) | |
for i := 0; i < b.N; i++ { | |
a.increment() | |
} | |
} | |
goos: linux | |
goarch: amd64 | |
pkg: github.com/dgraph-io/badger/table | |
BenchmarkInterface-8 2000000000 2.01 ns/op 0 B/op 0 allocs/op | |
PASS | |
ok github.com/dgraph-io/badger/table 4.224s | |
Success: Benchmarks passed. | |
goos: linux | |
goarch: amd64 | |
pkg: github.com/dgraph-io/badger/table | |
BenchmarkConcreteType-8 2000000000 1.50 ns/op 0 B/op 0 allocs/op | |
PASS | |
ok github.com/dgraph-io/badger/table 3.158s | |
Success: Benchmarks passed. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment