-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce6cad0
commit 14831d0
Showing
2 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |