Esempio n. 1
0
// BatchWriteBenchmark benchmarks the Write method of the given
// graphstore.Service.  The number of updates per write is configured with
// batchSize.
func BatchWriteBenchmark(b *testing.B, create CreateFunc, batchSize int) {
	b.StopTimer()
	gs, destroy, err := create()
	testutil.FatalOnErr(b, "CreateFunc error: %v", err)
	defer func() {
		testutil.FatalOnErr(b, "gs close error: %v", gs.Close(ctx))
		testutil.FatalOnErr(b, "DestroyFunc error: %v", destroy())
	}()

	updates := make([]spb.WriteRequest_Update, batchSize)
	req := &spb.WriteRequest{
		Source: &spb.VName{},
		Update: make([]*spb.WriteRequest_Update, batchSize),
	}
	for i := 0; i < b.N; i++ {
		randVName(req.Source, keySize)

		for j := 0; j < batchSize; j++ {
			randUpdate(&updates[j], keySize)
			req.Update[j] = &updates[j]
		}

		testutil.FatalOnErr(b, "write error: %v", gs.Write(ctx, req))
	}
}
Esempio n. 2
0
// BatchWriteBenchmark benchmarks the Write method of the given keyvalue.DB.
// The number of updates per write is configured with batchSize.
func BatchWriteBenchmark(b *testing.B, create CreateFunc, batchSize int) {
	db, destroy, err := create()
	testutil.FatalOnErr(b, "CreateFunc error: %v", err)
	defer func() {
		testutil.FatalOnErr(b, "db close error: %v", db.Close())
		testutil.FatalOnErr(b, "DestroyFunc error: %v", destroy())
	}()

	keyBuf := make([]byte, keySize)
	valBuf := make([]byte, valSize)
	for i := 0; i < b.N; i++ {
		wr, err := db.Writer()
		testutil.FatalOnErr(b, "writer error: %v", err)
		for j := 0; j < batchSize; j++ {
			testutil.RandBytes(keyBuf)
			testutil.RandBytes(valBuf)
			testutil.FatalOnErr(b, "write error: %v", wr.Write(keyBuf, valBuf))
		}
		testutil.FatalOnErr(b, "writer close error: %v", wr.Close())
	}
}