Skip to content

Commit 68a5c07

Browse files
committed
Add benchmark
1 parent b6fbf10 commit 68a5c07

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

maxflow_test.go

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

@@ -67,3 +68,19 @@ func TestMaxFlow(t *testing.T) {
6768
t.Errorf("MaxFlow(3, 1) %s", mess)
6869
}
6970
}
71+
72+
73+
func BenchmarkMaxFlow(b *testing.B) {
74+
n := 50
75+
b.StopTimer()
76+
g := New(n)
77+
for i := 0; i < n; i++ {
78+
for j := i; j < n; j++ {
79+
g.AddCost(i, j, int64(rand.Int()))
80+
}
81+
}
82+
b.StartTimer()
83+
for i := 0; i < b.N; i++ {
84+
_, _ = MaxFlow(g, 0, n-1)
85+
}
86+
}

0 commit comments

Comments
 (0)