mirror of
https://github.com/gonum/gonum.git
synced 2025-12-24 13:47:56 +08:00
graph: add benchmarks for topo.Sort(Stabilized)
This commit is contained in:
committed by
Dan Kortschak
parent
affaa34094
commit
1bc1de45aa
@@ -27,6 +27,10 @@ var (
|
||||
gnpUndirected_100_tenth = gnpUndirected(100, 0.1)
|
||||
gnpUndirected_10_half = gnpUndirected(10, 0.5)
|
||||
gnpUndirected_100_half = gnpUndirected(100, 0.5)
|
||||
|
||||
pathDirected_10 = pathDirected(10)
|
||||
pathDirected_1000 = pathDirected(1e3)
|
||||
pathDirected_100000 = pathDirected(1e5)
|
||||
)
|
||||
|
||||
func gnpDirected(n int, p float64) graph.Directed {
|
||||
@@ -47,6 +51,16 @@ func gnpUndirected(n int, p float64) graph.Undirected {
|
||||
return g
|
||||
}
|
||||
|
||||
func pathDirected(n int) graph.Directed {
|
||||
g := simple.NewDirectedGraph()
|
||||
var idSet gen.IDSet
|
||||
for i := 0; i < n; i++ {
|
||||
idSet = append(idSet, int64(i))
|
||||
}
|
||||
gen.Path(g, idSet)
|
||||
return g
|
||||
}
|
||||
|
||||
func benchmarkTarjanSCC(b *testing.B, g graph.Directed) {
|
||||
var sccs [][]graph.Node
|
||||
for i := 0; i < b.N; i++ {
|
||||
@@ -78,7 +92,9 @@ func BenchmarkTarjanSCCGnp_1000_half(b *testing.B) {
|
||||
|
||||
func benchmarkDirectedCyclesIn(b *testing.B, g graph.Directed) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
DirectedCyclesIn(g)
|
||||
if len(DirectedCyclesIn(g)) == 0 {
|
||||
b.Fatal("unexpected zero-sized cycles set")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +107,9 @@ func BenchmarkDirectedCyclesInGnp_10_half(b *testing.B) {
|
||||
|
||||
func benchmarkUndirectedCyclesIn(b *testing.B, g graph.Undirected) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
UndirectedCyclesIn(g)
|
||||
if len(UndirectedCyclesIn(g)) == 0 {
|
||||
b.Fatal("unexpected zero-sized cycles set")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,3 +125,75 @@ func BenchmarkUndirectedCyclesInGnp_10_half(b *testing.B) {
|
||||
func BenchmarkUndirectedCyclesInGnp_100_half(b *testing.B) {
|
||||
benchmarkUndirectedCyclesIn(b, gnpUndirected_100_half)
|
||||
}
|
||||
|
||||
func benchmarkSort(b *testing.B, g graph.Directed) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := Sort(g); err != nil {
|
||||
b.FailNow()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkSortGnp_10_tenth(b *testing.B) {
|
||||
benchmarkSort(b, gnpDirected_10_tenth)
|
||||
}
|
||||
func BenchmarkSortGnp_100_tenth(b *testing.B) {
|
||||
benchmarkSort(b, gnpDirected_100_tenth)
|
||||
}
|
||||
func BenchmarkSortGnp_1000_tenth(b *testing.B) {
|
||||
benchmarkSort(b, gnpDirected_1000_tenth)
|
||||
}
|
||||
func BenchmarkSortGnp_10_half(b *testing.B) {
|
||||
benchmarkSort(b, gnpDirected_10_half)
|
||||
}
|
||||
func BenchmarkSortGnp_100_half(b *testing.B) {
|
||||
benchmarkSort(b, gnpDirected_100_half)
|
||||
}
|
||||
func BenchmarkSortGnp_1000_half(b *testing.B) {
|
||||
benchmarkSort(b, gnpDirected_1000_half)
|
||||
}
|
||||
func BenchmarkSortPath_10(b *testing.B) {
|
||||
benchmarkSort(b, pathDirected_10)
|
||||
}
|
||||
func BenchmarkSortPath_1000(b *testing.B) {
|
||||
benchmarkSort(b, pathDirected_1000)
|
||||
}
|
||||
func BenchmarkSortPath_100000(b *testing.B) {
|
||||
benchmarkSort(b, pathDirected_100000)
|
||||
}
|
||||
|
||||
func benchmarkSortStabilized(b *testing.B, g graph.Directed) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := SortStabilized(g, nil); err != nil {
|
||||
b.FailNow()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkSortStabilizedGnp_10_tenth(b *testing.B) {
|
||||
benchmarkSortStabilized(b, gnpDirected_10_tenth)
|
||||
}
|
||||
func BenchmarkSortStabilizedGnp_100_tenth(b *testing.B) {
|
||||
benchmarkSortStabilized(b, gnpDirected_100_tenth)
|
||||
}
|
||||
func BenchmarkSortStabilizedGnp_1000_tenth(b *testing.B) {
|
||||
benchmarkSortStabilized(b, gnpDirected_1000_tenth)
|
||||
}
|
||||
func BenchmarkSortStabilizedGnp_10_half(b *testing.B) {
|
||||
benchmarkSortStabilized(b, gnpDirected_10_half)
|
||||
}
|
||||
func BenchmarkSortStabilizedGnp_100_half(b *testing.B) {
|
||||
benchmarkSortStabilized(b, gnpDirected_100_half)
|
||||
}
|
||||
func BenchmarkSortStabilizedGnp_1000_half(b *testing.B) {
|
||||
benchmarkSortStabilized(b, gnpDirected_1000_half)
|
||||
}
|
||||
func BenchmarkSortStabilizedPath_10(b *testing.B) {
|
||||
benchmarkSortStabilized(b, pathDirected_10)
|
||||
}
|
||||
func BenchmarkSortStabilizedPath_1000(b *testing.B) {
|
||||
benchmarkSortStabilized(b, pathDirected_1000)
|
||||
}
|
||||
func BenchmarkSortStabilizedPath_100000(b *testing.B) {
|
||||
benchmarkSortStabilized(b, pathDirected_100000)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user