mirror of
https://gitee.com/johng/gf
synced 2026-06-25 01:05:41 +08:00
gfpool增加基准测试
This commit is contained in:
@ -89,6 +89,8 @@ func (p *Pool) File() (*File, error) {
|
||||
if _, err := f.Seek(0, 2); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
f.Seek(0, 0)
|
||||
}
|
||||
if f.flag & os.O_CREATE > 0 {
|
||||
_, err := f.Stat()
|
||||
@ -103,10 +105,13 @@ func (p *Pool) File() (*File, error) {
|
||||
}
|
||||
}
|
||||
if f.flag & os.O_TRUNC > 0 {
|
||||
if err := f.Truncate(0); err != nil {
|
||||
return nil, err
|
||||
if stat, err := f.Stat(); err == nil {
|
||||
if stat.Size() > 0 {
|
||||
if err := f.Truncate(0); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
f.Seek(0, 0)
|
||||
}
|
||||
return f, nil
|
||||
}
|
||||
|
||||
21
g/os/gfpool/gfpool_test.go
Normal file
21
g/os/gfpool/gfpool_test.go
Normal file
@ -0,0 +1,21 @@
|
||||
package gfpool
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"os"
|
||||
)
|
||||
|
||||
func Benchmark_os_Open_Close(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
f, _ := os.OpenFile("/tmp/bench-test", os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0766)
|
||||
f.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_gfpool_Open_Close(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
f, _ := Open("/tmp/bench-test", os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0766)
|
||||
f.Close()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user