Skip to content

Commit

Permalink
add benchmark
Browse files Browse the repository at this point in the history
Signed-off-by: Jin Dong <djdongjin95@gmail.com>
  • Loading branch information
djdongjin committed Aug 27, 2024
1 parent 9aa8de8 commit 6b97a08
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/gc/gc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package gc

import (
"context"
"fmt"
"reflect"
"testing"
)
Expand Down Expand Up @@ -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"}
Expand Down

0 comments on commit 6b97a08

Please sign in to comment.