Skip to content

Commit 88e8987

Browse files
committed
Add benchmark
1 parent f5a1472 commit 88e8987

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

path_test.go

Lines changed: 15 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

@@ -48,3 +49,17 @@ func TestShortestPath(t *testing.T) {
4849
t.Errorf("ShortestPath->dist %s", mess)
4950
}
5051
}
52+
53+
func BenchmarkShortestPaths(b *testing.B) {
54+
n := 1000
55+
b.StopTimer()
56+
g := New(n)
57+
for i := 0; i < n; i++ {
58+
g.Add(0, rand.Intn(n))
59+
g.Add(rand.Intn(n), rand.Intn(n))
60+
}
61+
b.StartTimer()
62+
for i := 0; i < b.N; i++ {
63+
_, _ = ShortestPaths(g, 0)
64+
}
65+
}

0 commit comments

Comments
 (0)