Skip to content

Commit

Permalink
dag benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
jbardin committed Jan 8, 2020
1 parent c3a58db commit b4d7cee
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions dag/dag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,63 @@ func TestAcyclicGraphWalk_error(t *testing.T) {

}

func BenchmarkDAG(b *testing.B) {
for i := 0; i < b.N; i++ {
count := 150
b.StopTimer()
g := &AcyclicGraph{}

// create 3 layers of fully connected nodes
// layer A
for i := 0; i < count; i++ {
g.Add(fmt.Sprintf("A%d", i))
}

// layer B
for i := 0; i < count; i++ {
B := fmt.Sprintf("B%d", i)
g.Add(fmt.Sprintf(B))
for j := 0; j < count; j++ {
g.Connect(BasicEdge(B, fmt.Sprintf("A%d", j)))
}
}

// layer C
for i := 0; i < count; i++ {
c := fmt.Sprintf("C%d", i)
g.Add(fmt.Sprintf(c))
for j := 0; j < count; j++ {
// connect them to previous layers so we have something that requires reduction
g.Connect(BasicEdge(c, fmt.Sprintf("A%d", j)))
g.Connect(BasicEdge(c, fmt.Sprintf("B%d", j)))
}
}

// layer D
for i := 0; i < count; i++ {
d := fmt.Sprintf("C%d", i)
g.Add(fmt.Sprintf(d))
for j := 0; j < count; j++ {
g.Connect(BasicEdge(d, fmt.Sprintf("A%d", j)))
g.Connect(BasicEdge(d, fmt.Sprintf("B%d", j)))
g.Connect(BasicEdge(d, fmt.Sprintf("C%d", j)))
}
}

b.StartTimer()
// Find dependencies for every node
for _, v := range g.Vertices() {
_, err := g.Ancestors(v)
if err != nil {
b.Fatal(err)
}
}

// reduce the final graph
g.TransitiveReduction()
}
}

func TestAcyclicGraph_ReverseDepthFirstWalk_WithRemoval(t *testing.T) {
var g AcyclicGraph
g.Add(1)
Expand Down

0 comments on commit b4d7cee

Please sign in to comment.