File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change
1
+ package example
2
+
3
+ import (
4
+ "testing"
5
+ "time"
6
+ )
7
+
8
+ func busyWait (duration time.Duration ) {
9
+ start := time .Now ()
10
+ for time .Since (start ) < duration {
11
+ // Busy wait loop
12
+ }
13
+ }
14
+
15
+ func BenchmarkSleep100ns (b * testing.B ) {
16
+ for i := 0 ; i < b .N ; i ++ {
17
+ busyWait (100 * time .Nanosecond )
18
+ }
19
+ }
20
+
21
+ func BenchmarkSleep1us (b * testing.B ) {
22
+ for i := 0 ; i < b .N ; i ++ {
23
+ busyWait (1 * time .Microsecond )
24
+ }
25
+ }
26
+
27
+ func BenchmarkSleep10us (b * testing.B ) {
28
+ for i := 0 ; i < b .N ; i ++ {
29
+ busyWait (10 * time .Microsecond )
30
+ }
31
+ }
32
+
33
+ func BenchmarkSleep100us (b * testing.B ) {
34
+ for i := 0 ; i < b .N ; i ++ {
35
+ busyWait (100 * time .Microsecond )
36
+ }
37
+ }
38
+
39
+ func BenchmarkSleep1ms (b * testing.B ) {
40
+ for i := 0 ; i < b .N ; i ++ {
41
+ busyWait (1 * time .Millisecond )
42
+ }
43
+ }
44
+
45
+ func BenchmarkSleep10ms (b * testing.B ) {
46
+ for i := 0 ; i < b .N ; i ++ {
47
+ busyWait (10 * time .Millisecond )
48
+ }
49
+ }
50
+
51
+ func BenchmarkSleep50ms (b * testing.B ) {
52
+ for i := 0 ; i < b .N ; i ++ {
53
+ busyWait (50 * time .Millisecond )
54
+ }
55
+ }
You can’t perform that action at this time.
0 commit comments