add benchmark
Signed-off-by: Jin Dong <djdongjin95@gmail.com>
This commit is contained in:
parent
9aa8de8e2c
commit
6b97a08eee
@ -18,6 +18,7 @@ package gc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"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) {
|
func TestConcurrentBasic(t *testing.T) {
|
||||||
roots := []string{"A", "C"}
|
roots := []string{"A", "C"}
|
||||||
all := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I"}
|
all := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I"}
|
||||||
|
Loading…
Reference in New Issue
Block a user