github.com/loov/hrtime@v1.0.3/_example/basic/main.go (about)

     1  // This program demonstrates the basic usage of the package.
     2  package main
     3  
     4  import (
     5  	"fmt"
     6  	"math/rand"
     7  	"time"
     8  
     9  	"github.com/loov/hrtime"
    10  )
    11  
    12  func main() {
    13  	start := hrtime.Now()
    14  	time.Sleep(1000 * time.Nanosecond)
    15  	fmt.Println(hrtime.Since(start))
    16  
    17  	const numberOfExperiments = 4096
    18  	bench := hrtime.NewBenchmark(numberOfExperiments)
    19  	for bench.Next() {
    20  		time.Sleep(1000 * time.Nanosecond)
    21  		if rand.Intn(2000) == 0 {
    22  			time.Sleep(time.Second)
    23  		}
    24  	}
    25  	fmt.Println(bench.Histogram(10))
    26  }
    27  
    28  // Example output:
    29  // 22.779µs
    30  //   avg 1.744377ms;  min 827.221µs;  p50 1.986758ms;  max 2.200263ms;
    31  //   p90 2.036338ms;  p99 2.150237ms;  p999 2.182397ms;  p9999 2.200263ms;
    32  //   827.221µs [  89] ██
    33  //         1ms [1064] █████████████████████████
    34  //       1.2ms [  46] █
    35  //       1.4ms [   0]
    36  //       1.6ms [   1]
    37  //       1.8ms [1698] ████████████████████████████████████████
    38  //         2ms [1197] ████████████████████████████
    39  //       2.2ms [   1]
    40  //       2.4ms [   0]
    41  //       2.6ms [   0]