-
Notifications
You must be signed in to change notification settings - Fork 11
/
stopwatch_test.go
67 lines (57 loc) · 1.2 KB
/
stopwatch_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
package hrtime_test
import (
"fmt"
"testing"
"time"
"github.com/loov/hrtime"
)
func ExampleStopwatch() {
const numberOfExperiments = 4096
bench := hrtime.NewStopwatch(numberOfExperiments)
for i := 0; i < numberOfExperiments; i++ {
go func() {
lap := bench.Start()
defer bench.Stop(lap)
time.Sleep(1000 * time.Nanosecond)
}()
}
bench.Wait()
fmt.Println(bench.Histogram(10))
}
func ExampleStopwatchTSC() {
const numberOfExperiments = 4096
bench := hrtime.NewStopwatchTSC(numberOfExperiments)
for i := 0; i < numberOfExperiments; i++ {
go func() {
lap := bench.Start()
defer bench.Stop(lap)
time.Sleep(1000 * time.Nanosecond)
}()
}
bench.Wait()
fmt.Println(bench.Histogram(10))
}
func TestStopwatch(t *testing.T) {
bench := hrtime.NewStopwatch(8)
for i := 0; i < 8; i++ {
go func() {
lap := bench.Start()
defer bench.Stop(lap)
time.Sleep(1000 * time.Nanosecond)
}()
}
bench.Wait()
t.Log(bench.Histogram(10))
}
func TestStopwatchTSC(t *testing.T) {
bench := hrtime.NewStopwatchTSC(8)
for i := 0; i < 8; i++ {
go func() {
lap := bench.Start()
defer bench.Stop(lap)
time.Sleep(1000 * time.Nanosecond)
}()
}
bench.Wait()
t.Log(bench.Histogram(10))
}