2021-09-28 19:04:36 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
|
|
|
|
//
|
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
|
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
|
|
2018-09-25 13:18:43 +08:00
|
|
|
package gfpool
|
|
|
|
|
|
|
|
|
|
import (
|
2019-06-19 09:06:52 +08:00
|
|
|
"os"
|
|
|
|
|
"testing"
|
2018-09-25 13:18:43 +08:00
|
|
|
)
|
|
|
|
|
|
2020-03-15 19:32:26 +08:00
|
|
|
func Benchmark_OS_Open_Close_ALLFlags(b *testing.B) {
|
2019-06-19 09:06:52 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2020-03-15 19:32:26 +08:00
|
|
|
f, err := os.OpenFile("/tmp/bench-test", os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
2019-06-19 09:06:52 +08:00
|
|
|
f.Close()
|
|
|
|
|
}
|
2018-09-25 13:18:43 +08:00
|
|
|
}
|
|
|
|
|
|
2020-03-15 19:32:26 +08:00
|
|
|
func Benchmark_GFPool_Open_Close_ALLFlags(b *testing.B) {
|
2019-06-19 09:06:52 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2020-03-15 19:32:26 +08:00
|
|
|
f, err := Open("/tmp/bench-test", os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
2019-06-19 09:06:52 +08:00
|
|
|
f.Close()
|
|
|
|
|
}
|
2018-09-25 13:18:43 +08:00
|
|
|
}
|
|
|
|
|
|
2020-03-15 19:32:26 +08:00
|
|
|
func Benchmark_OS_Open_Close_RDWR(b *testing.B) {
|
2019-06-19 09:06:52 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2020-03-15 19:32:26 +08:00
|
|
|
f, err := os.OpenFile("/tmp/bench-test", os.O_RDWR, 0666)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
2019-06-19 09:06:52 +08:00
|
|
|
f.Close()
|
|
|
|
|
}
|
2018-11-08 14:00:28 +08:00
|
|
|
}
|
|
|
|
|
|
2020-03-15 19:32:26 +08:00
|
|
|
func Benchmark_GFPool_Open_Close_RDWR(b *testing.B) {
|
2019-06-19 09:06:52 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2020-03-15 19:32:26 +08:00
|
|
|
f, err := Open("/tmp/bench-test", os.O_RDWR, 0666)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
2019-06-19 09:06:52 +08:00
|
|
|
f.Close()
|
|
|
|
|
}
|
2018-11-08 14:00:28 +08:00
|
|
|
}
|
|
|
|
|
|
2020-03-15 19:32:26 +08:00
|
|
|
func Benchmark_OS_Open_Close_RDONLY(b *testing.B) {
|
2019-06-19 09:06:52 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2020-03-15 19:32:26 +08:00
|
|
|
f, err := os.OpenFile("/tmp/bench-test", os.O_RDONLY, 0666)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
2019-06-19 09:06:52 +08:00
|
|
|
f.Close()
|
|
|
|
|
}
|
2018-11-08 14:00:28 +08:00
|
|
|
}
|
|
|
|
|
|
2020-03-15 19:32:26 +08:00
|
|
|
func Benchmark_GFPool_Open_Close_RDONLY(b *testing.B) {
|
2019-06-19 09:06:52 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2020-03-15 19:32:26 +08:00
|
|
|
f, err := Open("/tmp/bench-test", os.O_RDONLY, 0666)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
2019-06-19 09:06:52 +08:00
|
|
|
f.Close()
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-25 00:03:52 +08:00
|
|
|
|
|
|
|
|
func Benchmark_Stat(b *testing.B) {
|
|
|
|
|
f, err := os.Create("/tmp/bench-test-stat")
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
defer f.Close()
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
|
f.Stat()
|
|
|
|
|
}
|
|
|
|
|
}
|