forked from StackExchange/wmi
-
Notifications
You must be signed in to change notification settings - Fork 3
/
benchmark_test.go
79 lines (68 loc) · 1.84 KB
/
benchmark_test.go
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
67
68
69
70
71
72
73
74
75
76
77
78
79
// +build windows
package wmi
import "testing"
//Run all benchmarks (should run for at least 60s to get a stable number):
//go test -run=NONE -bench=. -benchtime=120s
// All Query benchmarks:
// go test -run=NONE -bench=Query -benchtime=120s
// go test -run=NONE -bench=Query_DefaultClient -benchtime=120s
func BenchmarkQuery_DefaultClient(b *testing.B) {
var dst []Win32_OperatingSystem
q := CreateQuery(&dst, "")
for n := 0; n < b.N; n++ {
errQuery := Query(q, &dst)
if errQuery != nil {
b.Fatalf("Query%d: %s", n, errQuery)
}
count := len(dst)
if count < 1 {
b.Fatalf("Query%d: no results found for Win32_OperatingSystem", n)
}
}
}
// go test -run=NONE -bench=Query_SWbemServices -benchtime=120s
func BenchmarkQuery_SWbemServices(b *testing.B) {
s, err := NewSWbemServices()
if err != nil {
b.Fatalf("InitializeSWbemServices: %s", err)
}
var dst []Win32_OperatingSystem
q := CreateQuery(&dst, "")
for n := 0; n < b.N; n++ {
errQuery := s.Query(q, &dst)
if errQuery != nil {
b.Fatalf("Query%d: %s", n, errQuery)
}
count := len(dst)
if count < 1 {
b.Fatalf("Query%d: no results found for Win32_OperatingSystem", n)
}
}
errClose := s.Close()
if errClose != nil {
b.Fatalf("Close: %s", errClose)
}
}
// go test -run=NONE -bench=Query_SWbemConnection -benchtime=120s
func BenchmarkQuery_SWbemConnection(b *testing.B) {
s, err := ConnectSWbemServices() // Note here
if err != nil {
b.Fatalf("InitializeSWbemServices: %s", err)
}
var dst []Win32_OperatingSystem
q := CreateQuery(&dst, "")
for n := 0; n < b.N; n++ {
errQuery := s.Query(q, &dst)
if errQuery != nil {
b.Fatalf("Query%d: %s", n, errQuery)
}
count := len(dst)
if count < 1 {
b.Fatalf("Query%d: no results found for Win32_OperatingSystem", n)
}
}
errClose := s.Close()
if errClose != nil {
b.Fatalf("Close: %s", errClose)
}
}