github.com/zhongdalu/gf@v1.0.0/g/os/gfpool/gfpool_z_bench_test.go (about)

     1  package gfpool
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  )
     7  
     8  func Benchmark_os_Open_Close_ALLFlags(b *testing.B) {
     9  	for i := 0; i < b.N; i++ {
    10  		f, _ := os.OpenFile("/tmp/bench-test", os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666)
    11  		f.Close()
    12  	}
    13  }
    14  
    15  func Benchmark_gfpool_Open_Close_ALLFlags(b *testing.B) {
    16  	for i := 0; i < b.N; i++ {
    17  		f, _ := Open("/tmp/bench-test", os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666)
    18  		f.Close()
    19  	}
    20  }
    21  
    22  func Benchmark_os_Open_Close_RDWR(b *testing.B) {
    23  	for i := 0; i < b.N; i++ {
    24  		f, _ := os.OpenFile("/tmp/bench-test", os.O_RDWR, 0666)
    25  		f.Close()
    26  	}
    27  }
    28  
    29  func Benchmark_gfpool_Open_Close_RDWR(b *testing.B) {
    30  	for i := 0; i < b.N; i++ {
    31  		f, _ := Open("/tmp/bench-test", os.O_RDWR, 0666)
    32  		f.Close()
    33  	}
    34  }
    35  
    36  func Benchmark_os_Open_Close_RDONLY(b *testing.B) {
    37  	for i := 0; i < b.N; i++ {
    38  		f, _ := os.OpenFile("/tmp/bench-test", os.O_RDONLY, 0666)
    39  		f.Close()
    40  	}
    41  }
    42  
    43  func Benchmark_gfpool_Open_Close_RDONLY(b *testing.B) {
    44  	for i := 0; i < b.N; i++ {
    45  		f, _ := Open("/tmp/bench-test", os.O_RDONLY, 0666)
    46  		f.Close()
    47  	}
    48  }