github.com/zhongdalu/gf@v1.0.0/g/os/gtimer/gtimer_z_bench_test.go (about)

     1  // Copyright 2019 gf Author(https://github.com/zhongdalu/gf). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/zhongdalu/gf.
     6  
     7  package gtimer_test
     8  
     9  import (
    10  	"github.com/zhongdalu/gf/g/os/gtimer"
    11  	"testing"
    12  	"time"
    13  )
    14  
    15  var (
    16  	timer = gtimer.New(5, 30*time.Millisecond)
    17  )
    18  
    19  func Benchmark_Add(b *testing.B) {
    20  	for i := 0; i < b.N; i++ {
    21  		timer.Add(time.Hour, func() {
    22  
    23  		})
    24  	}
    25  }
    26  
    27  func Benchmark_StartStop(b *testing.B) {
    28  	for i := 0; i < b.N; i++ {
    29  		timer.Start()
    30  		timer.Stop()
    31  	}
    32  }