From 6b97a08eeec394bba6c77b2a8ffa09a1d0f4adf0 Mon Sep 17 00:00:00 2001 From: Jin Dong Date: Mon, 26 Aug 2024 18:30:51 -0700 Subject: [PATCH] add benchmark Signed-off-by: Jin Dong --- pkg/gc/gc_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pkg/gc/gc_test.go b/pkg/gc/gc_test.go index cde52c748..0d931f5ad 100644 --- a/pkg/gc/gc_test.go +++ b/pkg/gc/gc_test.go @@ -18,6 +18,7 @@ package gc import ( "context" + "fmt" "reflect" "testing" ) @@ -52,6 +53,28 @@ func TestTricolorBasic(t *testing.T) { } } +func BenchmarkTricolor(b *testing.B) { + roots := []string{"A", "C"} + refs := map[string][]string{ + "A": {"B", "C"}, + "B": {"A", "C"}, + "C": {"D", "F", "B"}, + "E": {"F", "G", "C"}, + "F": {"H", "C"}, + } + // assume 100 nodes can reach D. + for i := 0; i < 100; i++ { + ref := fmt.Sprintf("X%d", i) + refs["A"] = append(refs["A"], ref) + refs[ref] = []string{"D"} + } + + // Run the Add function b.N times to benchmark it. + for i := 0; i < b.N; i++ { + Tricolor(toNodes(roots), lookup(refs)) + } +} + func TestConcurrentBasic(t *testing.T) { roots := []string{"A", "C"} all := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I"}