Skip to content

Commit f5a1472

Browse files
committed
Add benchmark
1 parent db318b7 commit f5a1472

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

strong_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package graph
22

33
import (
4+
"math/rand"
45
"testing"
56
)
67

@@ -31,3 +32,16 @@ func TestStrongComponents(t *testing.T) {
3132
t.Errorf("StronglyConnected %s", mess)
3233
}
3334
}
35+
36+
func BenchmarkStrongComponents(b *testing.B) {
37+
n := 1000
38+
b.StopTimer()
39+
g := New(n)
40+
for i := 0; i < n; i++ {
41+
g.Add(rand.Intn(n), rand.Intn(n))
42+
}
43+
b.StartTimer()
44+
for i := 0; i < b.N; i++ {
45+
_ = StrongComponents(g)
46+
}
47+
}

0 commit comments

Comments
 (0)