]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: add interface microbenchmarks
authorDave Cheney <dave@cheney.net>
Wed, 11 Apr 2012 12:45:44 +0000 (22:45 +1000)
committerDave Cheney <dave@cheney.net>
Wed, 11 Apr 2012 12:45:44 +0000 (22:45 +1000)
2011 Mac Mini, Core i5 @ 2.3Ghz

BenchmarkConvT2E        50000000                40.4 ns/op
BenchmarkConvT2EBig     20000000               107 ns/op
BenchmarkConvT2I        100000000               28.9 ns/op
BenchmarkConvI2E        500000000                5.93 ns/op
BenchmarkConvI2I        100000000               19.0 ns/op
BenchmarkAssertE2T      100000000               14.1 ns/op
BenchmarkAssertE2TBig   100000000               17.8 ns/op
BenchmarkAssertE2I      100000000               21.3 ns/op
BenchmarkAssertI2T      100000000               14.3 ns/op
BenchmarkAssertI2I      100000000               20.8 ns/op
BenchmarkAssertI2E      500000000                5.58 ns/op

Pandaboard, 2 x Omap4 @ 1.2Ghz

BenchmarkConvT2E        10000000               215 ns/op
BenchmarkConvT2EBig      1000000              3697 ns/op
BenchmarkConvT2I         5000000               666 ns/op
BenchmarkConvI2E        50000000                42.4 ns/op
BenchmarkConvI2I         5000000               489 ns/op
BenchmarkAssertE2T      20000000                90.0 ns/op
BenchmarkAssertE2TBig   20000000                91.6 ns/op
BenchmarkAssertE2I       5000000               515 ns/op
BenchmarkAssertI2T      20000000               124 ns/op
BenchmarkAssertI2I       5000000               517 ns/op
BenchmarkAssertI2E      50000000                47.2 ns/op
BenchmarkAssertE2E      50000000                42.7 ns/op

R=minux.ma, rsc, fullung, bsiegert, dsymonds
CC=golang-dev
https://golang.org/cl/5777048

src/pkg/runtime/iface_test.go [new file with mode: 0644]

diff --git a/src/pkg/runtime/iface_test.go b/src/pkg/runtime/iface_test.go
new file mode 100644 (file)
index 0000000..fbbb2c9
--- /dev/null
@@ -0,0 +1,96 @@
+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package runtime_test
+
+import (
+       "bytes"
+       "io"
+       "testing"
+)
+
+var (
+       I   interface{}
+       J   int
+       B                 = new(bytes.Buffer)
+       W   io.Writer     = B
+       I2  interface{}   = B
+       R   io.ReadWriter = B
+       Big [2]*int
+)
+
+func BenchmarkConvT2E(b *testing.B) {
+       for i := 0; i < b.N; i++ {
+               I = 1
+       }
+}
+
+func BenchmarkConvT2EBig(b *testing.B) {
+       v := [2]*int{}
+       for i := 0; i < b.N; i++ {
+               I = v
+       }
+}
+
+func BenchmarkConvT2I(b *testing.B) {
+       for i := 0; i < b.N; i++ {
+               W = B
+       }
+}
+
+func BenchmarkConvI2E(b *testing.B) {
+       for i := 0; i < b.N; i++ {
+               I = W
+       }
+}
+
+func BenchmarkConvI2I(b *testing.B) {
+       for i := 0; i < b.N; i++ {
+               W = R
+       }
+}
+
+func BenchmarkAssertE2T(b *testing.B) {
+       I = 1
+       for i := 0; i < b.N; i++ {
+               J = I.(int)
+       }
+}
+
+func BenchmarkAssertE2TBig(b *testing.B) {
+       var v interface{} = [2]*int{}
+       for i := 0; i < b.N; i++ {
+               Big = v.([2]*int)
+       }
+}
+
+func BenchmarkAssertE2I(b *testing.B) {
+       for i := 0; i < b.N; i++ {
+               W = I2.(io.Writer)
+       }
+}
+
+func BenchmarkAssertI2T(b *testing.B) {
+       for i := 0; i < b.N; i++ {
+               B = W.(*bytes.Buffer)
+       }
+}
+
+func BenchmarkAssertI2I(b *testing.B) {
+       for i := 0; i < b.N; i++ {
+               W = R.(io.Writer)
+       }
+}
+
+func BenchmarkAssertI2E(b *testing.B) {
+       for i := 0; i < b.N; i++ {
+               I = R.(interface{})
+       }
+}
+
+func BenchmarkAssertE2E(b *testing.B) {
+       for i := 0; i < b.N; i++ {
+               I = I2.(interface{})
+       }
+}