From 1ac4f92299385c7532d778846d53c195840007e8 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 16 Nov 2014 21:41:05 +0100 Subject: [PATCH] Add benchmark for Chunk+Encrypt --- archiver_test.go | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 archiver_test.go diff --git a/archiver_test.go b/archiver_test.go new file mode 100644 index 000000000..529b2bb5f --- /dev/null +++ b/archiver_test.go @@ -0,0 +1,53 @@ +package khepri_test + +import ( + "bytes" + "io" + "math/rand" + "testing" + + "github.com/fd0/khepri/chunker" +) + +func get_random(seed, count int) []byte { + buf := make([]byte, count) + + rnd := rand.New(rand.NewSource(23)) + for i := 0; i < count; i += 4 { + r := rnd.Uint32() + buf[i] = byte(r) + buf[i+1] = byte(r >> 8) + buf[i+2] = byte(r >> 16) + buf[i+3] = byte(r >> 24) + } + + return buf +} + +func BenchmarkChunkEncrypt(b *testing.B) { + data := get_random(23, 10<<20) // 10MiB + + be := setupBackend(b) + defer teardownBackend(b, be) + key := setupKey(b, be, "geheim") + + b.ResetTimer() + b.SetBytes(int64(len(data))) + + for i := 0; i < b.N; i++ { + ch := chunker.New(bytes.NewReader(data)) + + for { + chunk_data, err := ch.Next() + + if err == io.EOF { + break + } + + ok(b, err) + + _, err = key.Encrypt(chunk_data.Data) + ok(b, err) + } + } +}