Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Unified Diff: tumble/tumble_test.go

Issue 2592753002: Create unbuffered Tumble entry point for LogDog. (Closed)
Patch Set: Add bench, update. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tumble/tumble.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tumble/tumble_test.go
diff --git a/tumble/tumble_test.go b/tumble/tumble_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..aeac8b773c6f29b776748a6544347e0bf4443527
--- /dev/null
+++ b/tumble/tumble_test.go
@@ -0,0 +1,85 @@
+// Copyright 2015 The LUCI Authors. All rights reserved.
+// Use of this source code is governed under the Apache License, Version 2.0
+// that can be found in the LICENSE file.
+
+package tumble
+
+import (
+ "fmt"
+ "testing"
+
+ ds "github.com/luci/gae/service/datastore"
+
+ "golang.org/x/net/context"
+)
+
+func init() {
+ Register(&registerBenchmarkMutation{})
+}
+
+type registerBenchmarkMutation struct {
+ Parent *ds.Key
+ ID string
+ Rounds int
+}
+
+func (m *registerBenchmarkMutation) RollForward(c context.Context) ([]Mutation, error) {
+ type testEntity struct {
+ Parent *ds.Key `gae:"$parent"`
+ Kind string `gae:"$kind,test"`
+ ID string `gae:"$id"`
+
+ Name string
+ }
+
+ // Perform a Get, Query, then Put.
+ e := testEntity{Parent: m.Root(c), ID: m.ID}
+ if err := ds.Get(c, &e); err != nil && err != ds.ErrNoSuchEntity {
+ return nil, err
+ }
+
+ var all []*testEntity
+ if err := ds.GetAll(c, ds.NewQuery("test").Ancestor(m.Parent), &all); err != nil {
+ return nil, err
+ }
+
+ ents := make([]*testEntity, m.Rounds)
+ for i := range ents {
+ ents[i] = &testEntity{Parent: m.Parent, ID: fmt.Sprintf("%s.%d", m.ID, i)}
+ }
+ if err := ds.Put(c, ents); err != nil {
+ return nil, err
+ }
+
+ // Put the entity, add some new Mutations at the end.
+ return []Mutation{
+ &registerBenchmarkMutation{m.Parent, "bar", m.Rounds},
+ &registerBenchmarkMutation{m.Parent, "baz", m.Rounds},
+ }, nil
+}
+
+func (m *registerBenchmarkMutation) Root(c context.Context) *ds.Key { return m.Parent }
+
+func runRegisterBenchmark(b *testing.B, reg func(context.Context, Mutation) error) {
+ var t Testing
+ c := t.Context()
+ mut := registerBenchmarkMutation{ds.MakeKey(c, "parent", 1), "foo", 500}
+
+ b.ResetTimer()
+ if err := reg(c, &mut); err != nil {
+ panic(err)
+ }
+}
+
+func BenchmarkRegisterWithRunMutation(b *testing.B) {
+ runRegisterBenchmark(b, RunMutation)
+}
+
+func BenchmarkRegisterWithRunUnbuffered(b *testing.B) {
+ runRegisterBenchmark(b, func(c context.Context, m Mutation) error {
+ return RunUnbuffered(c, m.Root(c), m.RollForward)
+ })
+}
+
+//BenchmarkRegisterWithRunMutation-32 1000000000 0.52 ns/op
+//BenchmarkRegisterWithRunUnbuffered-32 1000000000 0.22 ns/op
« no previous file with comments | « tumble/tumble.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698