github.com/zhongdalu/gf@v1.0.0/g/os/grpool/grpool_bench_1_test.go (about)

     1  // Copyright 2017 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  // go test *.go -bench=".*"
     8  
     9  package grpool_test
    10  
    11  import (
    12  	"github.com/zhongdalu/gf/g/os/grpool"
    13  	"testing"
    14  )
    15  
    16  func increment() {
    17  	for i := 0; i < 1000000; i++ {
    18  	}
    19  }
    20  
    21  func BenchmarkGrpool_1(b *testing.B) {
    22  	for i := 0; i < b.N; i++ {
    23  		grpool.Add(increment)
    24  	}
    25  }
    26  
    27  func BenchmarkGoroutine_1(b *testing.B) {
    28  	for i := 0; i < b.N; i++ {
    29  		go increment()
    30  	}
    31  }