-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench_test.go
More file actions
66 lines (54 loc) · 1.4 KB
/
Copy pathbench_test.go
File metadata and controls
66 lines (54 loc) · 1.4 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 goref
import (
"fmt"
"testing"
"time"
)
var nsec int64
var snap Snapshot
// BenchmarkMeasureTime -- Measures how long measuring the time takes (using time.Now() and Time.Sub())
func BenchmarkMeasureTime(b *testing.B) {
for n := 0; n < b.N; n++ {
start := time.Now()
end := time.Now()
nsec = end.Sub(start).Nanoseconds()
}
}
// BenchmarkRefDeref -- Measures how long an empty Ref().Deref() call takes
func BenchmarkRefDeref(b *testing.B) {
g := NewGoRef()
for n := 0; n < b.N; n++ {
g.Ref("hello").Deref()
}
//snap := g.Clone()
//j, _ := json.Marshal(snap.Data)
//log.Printf("data: %s", j)
}
// BenchmarkRefDeref -- Measures how long an empty Ref().Deref() call takes (doing the Deref() in a defer statement)
func BenchmarkRefDerefDeferred(b *testing.B) {
g := NewGoRef()
for n := 0; n < b.N; n++ {
r := g.Ref("hello")
defer r.Deref()
}
//snap := g.Clone()
//j, _ := json.Marshal(snap.Data)
//log.Printf("data: %s", j)
}
// benchmarkGetSnapshot -- Measure how long it takes to create a deep copy of the snapshot data
func benchmarkGetSnapshot(count int, b *testing.B) {
// setup
g := NewGoRef()
for n := 0; n < count; n++ {
g.Ref(fmt.Sprintf("ref%d", n)).Deref()
}
for n := 0; n < b.N; n++ {
snap = g.GetSnapshot()
}
}
func BenchmarkGetSnapshot100(b *testing.B) {
benchmarkGetSnapshot(100, b)
}
func BenchmarkGetSnapshot1000(b *testing.B) {
benchmarkGetSnapshot(1000, b)
}