File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 11package graph
22
33import (
4+ "math/rand"
45 "testing"
56)
67
@@ -80,3 +81,35 @@ func TestAcyclic(t *testing.T) {
8081 t .Errorf ("Acyclic %s" , mess )
8182 }
8283}
84+
85+ func BenchmarkAcyclic (b * testing.B ) {
86+ n := 1000
87+ b .StopTimer ()
88+ g := New (n )
89+ for i := 0 ; i < 2 * n ; i ++ {
90+ v , w := rand .Intn (n ), rand .Intn (n )
91+ if v < w {
92+ g .AddBoth (v , w )
93+ }
94+ }
95+ b .StartTimer ()
96+ for i := 0 ; i < b .N ; i ++ {
97+ _ = Acyclic (g )
98+ }
99+ }
100+
101+ func BenchmarkTopSort (b * testing.B ) {
102+ n := 1000
103+ b .StopTimer ()
104+ g := New (n )
105+ for i := 0 ; i < 2 * n ; i ++ {
106+ v , w := rand .Intn (n ), rand .Intn (n )
107+ if v < w {
108+ g .AddBoth (v , w )
109+ }
110+ }
111+ b .StartTimer ()
112+ for i := 0 ; i < b .N ; i ++ {
113+ _ , _ = TopSort (g )
114+ }
115+ }
You can’t perform that action at this time.
0 commit comments