github.com/loov/hrtime@v1.0.3/benchmark_test.go (about) 1 package hrtime_test 2 3 import ( 4 "fmt" 5 "testing" 6 "time" 7 8 "github.com/loov/hrtime" 9 ) 10 11 func ExampleBenchmark() { 12 const numberOfExperiments = 4096 13 bench := hrtime.NewBenchmark(numberOfExperiments) 14 for bench.Next() { 15 time.Sleep(1000 * time.Nanosecond) 16 } 17 fmt.Println(bench.Histogram(10)) 18 } 19 20 func ExampleBenchmarkTSC() { 21 const numberOfExperiments = 4096 22 bench := hrtime.NewBenchmarkTSC(numberOfExperiments) 23 for bench.Next() { 24 time.Sleep(1000 * time.Nanosecond) 25 } 26 fmt.Println(bench.Histogram(10)) 27 } 28 29 func TestBenchmark(t *testing.T) { 30 bench := hrtime.NewBenchmark(8) 31 for bench.Next() { 32 time.Sleep(1000 * time.Nanosecond) 33 } 34 t.Log(bench.Histogram(10)) 35 } 36 37 func TestBenchmarkTSC(t *testing.T) { 38 bench := hrtime.NewBenchmarkTSC(8) 39 for bench.Next() { 40 time.Sleep(1000 * time.Nanosecond) 41 } 42 t.Log(bench.Histogram(10)) 43 }