github.com/wangyougui/gf/v2@v2.6.5/os/gfpool/gfpool_z_bench_test.go (about) 1 // Copyright GoFrame Author(https://goframe.org). 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/wangyougui/gf. 6 7 package gfpool 8 9 import ( 10 "os" 11 "testing" 12 ) 13 14 func Benchmark_OS_Open_Close_ALLFlags(b *testing.B) { 15 for i := 0; i < b.N; i++ { 16 f, err := os.OpenFile("/tmp/bench-test", os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) 17 if err != nil { 18 panic(err) 19 } 20 f.Close() 21 } 22 } 23 24 func Benchmark_GFPool_Open_Close_ALLFlags(b *testing.B) { 25 for i := 0; i < b.N; i++ { 26 f, err := Open("/tmp/bench-test", os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) 27 if err != nil { 28 panic(err) 29 } 30 f.Close() 31 } 32 } 33 34 func Benchmark_OS_Open_Close_RDWR(b *testing.B) { 35 for i := 0; i < b.N; i++ { 36 f, err := os.OpenFile("/tmp/bench-test", os.O_RDWR, 0666) 37 if err != nil { 38 panic(err) 39 } 40 f.Close() 41 } 42 } 43 44 func Benchmark_GFPool_Open_Close_RDWR(b *testing.B) { 45 for i := 0; i < b.N; i++ { 46 f, err := Open("/tmp/bench-test", os.O_RDWR, 0666) 47 if err != nil { 48 panic(err) 49 } 50 f.Close() 51 } 52 } 53 54 func Benchmark_OS_Open_Close_RDONLY(b *testing.B) { 55 for i := 0; i < b.N; i++ { 56 f, err := os.OpenFile("/tmp/bench-test", os.O_RDONLY, 0666) 57 if err != nil { 58 panic(err) 59 } 60 f.Close() 61 } 62 } 63 64 func Benchmark_GFPool_Open_Close_RDONLY(b *testing.B) { 65 for i := 0; i < b.N; i++ { 66 f, err := Open("/tmp/bench-test", os.O_RDONLY, 0666) 67 if err != nil { 68 panic(err) 69 } 70 f.Close() 71 } 72 } 73 74 func Benchmark_Stat(b *testing.B) { 75 f, err := os.Create("/tmp/bench-test-stat") 76 if err != nil { 77 panic(err) 78 } 79 defer f.Close() 80 for i := 0; i < b.N; i++ { 81 f.Stat() 82 } 83 }