1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
package bench_test
import (
"context"
"fmt"
"os"
"syscall"
"testing"
"github.com/anacrolix/fuse"
"github.com/anacrolix/fuse/fs"
"github.com/anacrolix/fuse/fs/fstestutil"
"github.com/anacrolix/fuse/fs/fstestutil/spawntest/httpjson"
)
type benchLookupDir struct {
fstestutil.Dir
}
var _ fs.NodeRequestLookuper = (*benchLookupDir)(nil)
func (f *benchLookupDir) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.LookupResponse) (fs.Node, error) {
return nil, syscall.ENOENT
}
type benchLookupRequest struct {
Path string
N int
}
func doBenchLookup(ctx context.Context, req benchLookupRequest) (*struct{}, error) {
for i := 0; i < req.N; i++ {
if _, err := os.Stat(req.Path); !os.IsNotExist(err) {
return nil, fmt.Errorf("Stat: wrong error: %v", err)
}
}
return &struct{}{}, nil
}
var benchLookupHelper = helpers.Register("benchLookup", httpjson.ServePOST(doBenchLookup))
func BenchmarkLookup(b *testing.B) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
f := &benchLookupDir{}
mnt, err := fstestutil.MountedT(b, fstestutil.SimpleFS{f}, nil)
if err != nil {
b.Fatal(err)
}
defer mnt.Close()
control := benchLookupHelper.Spawn(ctx, b)
defer control.Close()
name := mnt.Dir + "/does-not-exist"
req := benchLookupRequest{
Path: name,
N: b.N,
}
var nothing struct{}
b.ResetTimer()
if err := control.JSON("/").Call(ctx, req, ¬hing); err != nil {
b.Fatalf("calling helper: %v", err)
}
}
|