From de38011dd25f37c651e9d9e8285998d52ce961db Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Tue, 14 Aug 2018 00:56:15 +0300 Subject: [PATCH] Add simple benchmark for SnapshotCollection.ForEach() --- deb/snapshot_bench_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 deb/snapshot_bench_test.go diff --git a/deb/snapshot_bench_test.go b/deb/snapshot_bench_test.go new file mode 100644 index 00000000..19997c2c --- /dev/null +++ b/deb/snapshot_bench_test.go @@ -0,0 +1,38 @@ +package deb + +import ( + "fmt" + "os" + "testing" + + "github.com/aptly-dev/aptly/database" +) + +func BenchmarkSnapshotCollectionForEach(b *testing.B) { + const count = 1024 + + tmpDir := os.TempDir() + defer os.RemoveAll(tmpDir) + + db, _ := database.NewOpenDB(tmpDir) + defer db.Close() + + collection := NewSnapshotCollection(db) + + for i := 0; i < count; i++ { + snapshot := NewSnapshotFromRefList(fmt.Sprintf("snapshot%d", i), nil, NewPackageRefList(), fmt.Sprintf("Snapshot number %d", i)) + if collection.Add(snapshot) != nil { + b.FailNow() + } + } + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + collection = NewSnapshotCollection(db) + + collection.ForEach(func(s *Snapshot) error { + return nil + }) + } +}