diff options
author | Fumitoshi Ukai <fumitoshi.ukai@gmail.com> | 2015-06-18 15:36:57 +0900 |
---|---|---|
committer | Fumitoshi Ukai <fumitoshi.ukai@gmail.com> | 2015-06-18 15:36:57 +0900 |
commit | b8acae94bc5b6494f51fe1acf32df5d72d412562 (patch) | |
tree | c0e114c693abdacc5690ec3adf8dd1161c8983d1 /expr_test.go | |
parent | 7c9aa9f17d5f8f27aed62b5520b8fbc6be0103ac (diff) | |
download | kati-b8acae94bc5b6494f51fe1acf32df5d72d412562.tar.gz |
reduce runtime.convT2I -> runtime.newobject -> runtime.mallocgc
conversion from value to interface is more expensive than
conversion from pointer to interface.
package main
import "testing"
type I interface {
String() string
}
type val struct {
s string
}
func (v val) String() string { return v.s }
type ptr struct {
s string
}
func (p *ptr) String() string { return p.s }
func BenchmarkT2IForValue(b *testing.B) {
var intf I
for i := 0; i < b.N; i++ {
intf = val{"abc"}
}
_ = intf
}
func BenchmarkT2IForPtr(b *testing.B) {
var intf I
for i := 0; i < b.N; i++ {
intf = &ptr{"abc"}
}
_ = intf
}
% go test -bench . a_test.go
testing: warning: no tests to run
PASS
BenchmarkT2IForValue 20000000 90.9 ns/op
BenchmarkT2IForPtr 20000000 76.8 ns/op
ok command-line-arguments 3.539s
Diffstat (limited to 'expr_test.go')
-rw-r--r-- | expr_test.go | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/expr_test.go b/expr_test.go index dbf715a..9b776e0 100644 --- a/expr_test.go +++ b/expr_test.go @@ -47,11 +47,11 @@ func TestParseExpr(t *testing.T) { }, { in: "$foo", - val: Expr{varref{varname: literal("f")}, literal("oo")}, + val: Expr{&varref{varname: literal("f")}, literal("oo")}, }, { in: "$(foo)", - val: varref{varname: literal("foo")}, + val: &varref{varname: literal("foo")}, }, { in: "$(foo:.c=.o)", @@ -68,13 +68,13 @@ func TestParseExpr(t *testing.T) { fclosure: fclosure{ args: []Value{ literal("(subst"), - varref{ + &varref{ varname: literal("space"), }, - varref{ + &varref{ varname: literal(","), }, - varref{ + &varref{ varname: literal("foo"), }, }, @@ -89,15 +89,15 @@ func TestParseExpr(t *testing.T) { fclosure: fclosure{ args: []Value{ literal("(subst"), - varref{ + &varref{ varname: literal("space"), }, - varref{ + &varref{ varname: literal(""), }, Expr{ literal(","), - varref{ + &varref{ varname: literal("foo"), }, }, @@ -183,10 +183,10 @@ func TestParseExpr(t *testing.T) { fclosure: fclosure{ args: []Value{ literal("(and"), - varref{ + &varref{ varname: literal("TRUE"), }, - varref{ + &varref{ varname: literal("X"), }, }, @@ -245,7 +245,7 @@ func TestParseExpr(t *testing.T) { val: &funcEvalAssign{ lhs: "foo", op: ":=", - rhs: varref{ + rhs: &varref{ literal("bar"), }, }, |