From 46a62438d9c5bfd5605dd2115e72549427fb1faf Mon Sep 17 00:00:00 2001 From: Khosrow Afroozeh Date: Wed, 3 Dec 2014 18:00:26 +0100 Subject: [PATCH] more benchmarks --- packer.go | 2 +- performance/bench_get_test.go | 38 +++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/packer.go b/packer.go index ec5dfe80..2f1ff45f 100644 --- a/packer.go +++ b/packer.go @@ -57,7 +57,7 @@ func packAnyMap(val map[interface{}]interface{}) ([]byte, error) { func newPacker() *packer { p := &packer{ - buffer: bytes.NewBuffer(make([]byte, 0, 256)), + buffer: bytes.NewBuffer(make([]byte, 0, 64)), } return p diff --git a/performance/bench_get_test.go b/performance/bench_get_test.go index f551738b..4c4d2f90 100644 --- a/performance/bench_get_test.go +++ b/performance/bench_get_test.go @@ -45,7 +45,7 @@ func doGet(set string, b *testing.B) { } } -func Benchmark_Get___________Int(b *testing.B) { +func Benchmark_Get_________Int64(b *testing.B) { set := "get_bench_integer" bins := []*Bin{NewBin("b", rand.Int63())} makeDataForGetBench(set, bins) @@ -55,6 +55,16 @@ func Benchmark_Get___________Int(b *testing.B) { doGet(set, b) } +func Benchmark_Get_________Int32(b *testing.B) { + set := "get_bench_integer" + bins := []*Bin{NewBin("b", rand.Int31())} + makeDataForGetBench(set, bins) + b.N = 1000 + runtime.GC() + b.ResetTimer() + doGet(set, b) +} + func Benchmark_Get_String______1(b *testing.B) { set := "get_bench_str_1" bins := []*Bin{NewBin("b", strings.Repeat("s", 1))} @@ -94,6 +104,7 @@ func Benchmark_Get_String___1000(b *testing.B) { makeDataForGetBench(set, bins) doGet(set, b) } + func Benchmark_Get_String__10000(b *testing.B) { set := "get_bench_str_10000" bins := []*Bin{NewBin("b", strings.Repeat("s", 10000))} @@ -103,13 +114,36 @@ func Benchmark_Get_String__10000(b *testing.B) { makeDataForGetBench(set, bins) doGet(set, b) } + func Benchmark_Get_String_100000(b *testing.B) { go func() { log.Println(http.ListenAndServe(":6060", nil)) }() set := "get_bench_str_10000" bins := []*Bin{NewBin("b", strings.Repeat("s", 10000))} - b.N = 100000 + b.N = 1000 + runtime.GC() + b.ResetTimer() + makeDataForGetBench(set, bins) + doGet(set, b) +} + +func Benchmark_Get_Complex_Array(b *testing.B) { + set := "get_bench_str_10000" + // bins := []*Bin{NewBin("b", []interface{}{"a simple string", nil, rand.Int63(), []byte{12, 198, 211}})} + bins := []*Bin{NewBin("b", []interface{}{rand.Int63()})} + b.N = 1000 + runtime.GC() + b.ResetTimer() + makeDataForGetBench(set, bins) + doGet(set, b) +} + +func Benchmark_Get_Complex_Map(b *testing.B) { + set := "get_bench_str_10000" + // bins := []*Bin{NewBin("b", []interface{}{"a simple string", nil, rand.Int63(), []byte{12, 198, 211}})} + bins := []*Bin{NewBin("b", map[interface{}]interface{}{rand.Int63(): rand.Int63()})} + b.N = 1000 runtime.GC() b.ResetTimer() makeDataForGetBench(set, bins)