Skip to content

Instantly share code, notes, and snippets.

@reusee
Created October 5, 2012 10:28
Show Gist options
  • Select an option

  • Save reusee/3839137 to your computer and use it in GitHub Desktop.

Select an option

Save reusee/3839137 to your computer and use it in GitHub Desktop.
passing struct
package oo
import (
"testing"
"strings"
)
const n = 1024 * 1
func BenchmarkPassByCopy(b *testing.B) {
for i := 0; i < b.N; i++ {
passByCopy(Request{req: &Req{22, "test", "test", "i", []string{"f"}},
keys: [][]string{[]string{strings.Repeat("a", n)}}, op: 3, limit: 3,
values: []string{"3.3"}})
}
}
func BenchmarkPassByPointer(b *testing.B) {
for i := 0; i < b.N; i++ {
passByPointer(&Request{req: &Req{22, "test", "test", "i", []string{"f"}},
keys: [][]string{[]string{strings.Repeat("a", n)}}, op: 3, limit: 3,
values: []string{"3.3"}})
}
}
func passByCopy(in Request) {
_ = in.req.dbname
_ = in.req.table
_ = in.req.index
_ = in.req.fields
_ = in.keys
_ = in.op
_ = in.start
_ = in.limit
_ = in.filters
}
func passByPointer(in *Request) {
_ = in.req.dbname
_ = in.req.table
_ = in.req.index
_ = in.req.fields
_ = in.keys
_ = in.op
_ = in.start
_ = in.limit
_ = in.filters
}
type Req struct {
t int
dbname string
table string
index string
fields []string
}
type Request struct {
req *Req
keys [][]string
op uint8
start uint32
limit uint32
filters []*Filter
values []string
}
type Filter struct {
field string
op uint8
value string
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment