Skip to content

Commit

Permalink
add benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
mission-liao committed Dec 30, 2015
1 parent ce6cad0 commit 14831d0
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
96 changes: 96 additions & 0 deletions bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package dingo_test

import (
"fmt"
"sync/atomic"
"testing"

"github.com/mission-liao/dingo"
)

var testWork = func(count int, msg string) (string, int) {
return msg, count
}

func BenchmarkRaw(b *testing.B) {
var (
count = 1
msg = "test string"
)
for i := 0; i < b.N; i++ {
msg, count = testWork(count, msg)
}
}

type testSeqID struct {
i int32
}

func (me *testSeqID) NewID() (string, error) {
return fmt.Sprintf("%d", atomic.AddInt32(&me.i, 1)), nil
}

func BenchmarkLocal(b *testing.B) {
var (
err error
count = 1
msg = "test string"
)
defer func() {
if err != nil {
b.Fatalf("failed: %v\n", err)
}
}()

app, err := dingo.NewApp("local", nil)
if err != nil {
return
}

err = app.Register("myWork", testWork)
if err != nil {
return
}

_, err = app.Allocate("myWork", 10, 3)
if err != nil {
return
}

// setup for invoker
err = app.AddMarshaller(101, &struct {
dingo.GobMarshaller
testMyInvoker
}{
dingo.GobMarshaller{},
testMyInvoker{},
})
if err != nil {
return
}
err = app.SetMarshaller("myWork", 101, 101)
if err != nil {
return
}

// setup for idmaker
err = app.AddIDMaker(101, &testSeqID{})
if err != nil {
return
}
err = app.SetIDMaker("myWork", 101)
if err != nil {
return
}

// reset timer for preparation
b.ResetTimer()

var result *dingo.Result
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
result = dingo.NewResult(app.Call("myWork", nil, count, msg))
result.Wait(0)
}
})
}
15 changes: 15 additions & 0 deletions docs/benchmark.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
##Benchmark

All these benchmarks are done in a single node (my notebook) with these profiles:
```bash
Mem: 8G
CPU: 2.66 GHz Intel Core 2 Duo
```

###Local Mode
```bash
Macintosh:dingo ml$ go test -bench=Local -run=XXX -cpu=4
PASS
BenchmarkLocal-4 10000 228250 ns/op
ok github.com/mission-liao/dingo 2.334s
```

0 comments on commit 14831d0

Please sign in to comment.