forked from blokur/GraphDensityCut
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark_test.go
More file actions
66 lines (58 loc) · 1.23 KB
/
Copy pathbenchmark_test.go
File metadata and controls
66 lines (58 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"fmt"
"testing"
"github.com/askiada/GraphDensityCut/graph"
"github.com/askiada/GraphDensityCut/model"
"github.com/askiada/GraphDensityCut/session"
)
func ResetG(g []*model.Node) {
for i := range g {
g[i].Checked = false
for j := range g[i].Neighbors {
g[i].Neighbors[j].Check = false
}
}
}
var Result []*model.Node
func benchmarkDcut(nodes, edges int, b *testing.B) {
G := graph.Generate(nodes, edges)
b.ResetTimer()
sesh := &session.Session{}
for n := 0; n < b.N; n++ {
b.StopTimer()
ResetG(G)
b.StartTimer()
err := sesh.DensityConnectedTree(G, nil)
if err != nil {
panic(err)
}
sesh.Dcut()
}
Result = sesh.T
}
func CreateEdgesCountSlice(nodesCount int) []int {
s := []int{}
maxEdges := (nodesCount * (nodesCount - 1)) / 2
for i := maxEdges; i >= nodesCount; i = i / 2 {
s = append(s, i)
}
return s
}
func BenchmarkDcut(b *testing.B) {
nodesList := []int{
10,
25,
100,
200,
400,
}
for _, nodesCount := range nodesList {
edgesList := CreateEdgesCountSlice(nodesCount)
for i := len(edgesList) - 1; i >= 0; i-- {
b.Run(fmt.Sprintf("Nodes-%d:Edges%d", nodesCount, edgesList[i]), func(b *testing.B) {
benchmarkDcut(nodesCount, edgesList[i], b)
})
}
}
}