Skip to content

Commit d8e9b04

Browse files
committed
runtime: add interface microbenchmarks
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
1 parent 8cea1bf commit d8e9b04

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

src/pkg/runtime/iface_test.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Copyright 2012 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package runtime_test
6+
7+
import (
8+
"bytes"
9+
"io"
10+
"testing"
11+
)
12+
13+
var (
14+
I interface{}
15+
J int
16+
B = new(bytes.Buffer)
17+
W io.Writer = B
18+
I2 interface{} = B
19+
R io.ReadWriter = B
20+
Big [2]*int
21+
)
22+
23+
func BenchmarkConvT2E(b *testing.B) {
24+
for i := 0; i < b.N; i++ {
25+
I = 1
26+
}
27+
}
28+
29+
func BenchmarkConvT2EBig(b *testing.B) {
30+
v := [2]*int{}
31+
for i := 0; i < b.N; i++ {
32+
I = v
33+
}
34+
}
35+
36+
func BenchmarkConvT2I(b *testing.B) {
37+
for i := 0; i < b.N; i++ {
38+
W = B
39+
}
40+
}
41+
42+
func BenchmarkConvI2E(b *testing.B) {
43+
for i := 0; i < b.N; i++ {
44+
I = W
45+
}
46+
}
47+
48+
func BenchmarkConvI2I(b *testing.B) {
49+
for i := 0; i < b.N; i++ {
50+
W = R
51+
}
52+
}
53+
54+
func BenchmarkAssertE2T(b *testing.B) {
55+
I = 1
56+
for i := 0; i < b.N; i++ {
57+
J = I.(int)
58+
}
59+
}
60+
61+
func BenchmarkAssertE2TBig(b *testing.B) {
62+
var v interface{} = [2]*int{}
63+
for i := 0; i < b.N; i++ {
64+
Big = v.([2]*int)
65+
}
66+
}
67+
68+
func BenchmarkAssertE2I(b *testing.B) {
69+
for i := 0; i < b.N; i++ {
70+
W = I2.(io.Writer)
71+
}
72+
}
73+
74+
func BenchmarkAssertI2T(b *testing.B) {
75+
for i := 0; i < b.N; i++ {
76+
B = W.(*bytes.Buffer)
77+
}
78+
}
79+
80+
func BenchmarkAssertI2I(b *testing.B) {
81+
for i := 0; i < b.N; i++ {
82+
W = R.(io.Writer)
83+
}
84+
}
85+
86+
func BenchmarkAssertI2E(b *testing.B) {
87+
for i := 0; i < b.N; i++ {
88+
I = R.(interface{})
89+
}
90+
}
91+
92+
func BenchmarkAssertE2E(b *testing.B) {
93+
for i := 0; i < b.N; i++ {
94+
I = I2.(interface{})
95+
}
96+
}

0 commit comments

Comments
 (0)