From 869ba83c6d87c023cae275240965800169a23997 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Tue, 10 Feb 2015 21:59:18 +0100 Subject: [PATCH] Add Benchmarks for Scanner and Archiver --- archiver_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/archiver_test.go b/archiver_test.go index 64cb16bd0..5d3d6faca 100644 --- a/archiver_test.go +++ b/archiver_test.go @@ -2,6 +2,7 @@ package restic_test import ( "bytes" + "flag" "io" "math/rand" "testing" @@ -10,6 +11,8 @@ import ( "github.com/restic/restic/chunker" ) +var benchArchiveDirectory = flag.String("test.benchdir", "", "benchmark archiving a real directory") + func get_random(seed, count int) []byte { buf := make([]byte, count) @@ -117,3 +120,33 @@ func BenchmarkChunkEncryptParallel(b *testing.B) { } }) } + +func BenchmarkScanner(b *testing.B) { + if *benchArchiveDirectory == "" { + b.Skip("benchdir not set, skipping BenchmarkScanner") + } + + _, err := restic.NewScanner(nil).Scan(*benchArchiveDirectory) + ok(b, err) +} + +func BenchmarkArchiveDirectory(b *testing.B) { + if *benchArchiveDirectory == "" { + b.Skip("benchdir not set, skipping BenchmarkArchiveDirectory") + } + + be := setupBackend(b) + defer teardownBackend(b, be) + key := setupKey(b, be, "geheim") + server := restic.NewServerWithKey(be, key) + + tree, err := restic.NewScanner(nil).Scan(*benchArchiveDirectory) + ok(b, err) + + arch, err := restic.NewArchiver(server, nil) + ok(b, err) + + _, id, err := arch.Snapshot(*benchArchiveDirectory, tree, nil) + + b.Logf("snapshot archived as %v", id) +}