File: read_test.go

package info (click to toggle)
golang-github-hanwen-go-fuse 2.1.0%2Bgit20220822.58a7e14-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,292 kB
  • sloc: cpp: 78; sh: 43; makefile: 16
file content (58 lines) | stat: -rw-r--r-- 1,069 bytes parent folder | download | duplicates (2)
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
// Copyright 2021 the Go-FUSE Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package benchmark

import (
	"fmt"
	"os"
	"os/exec"
	"testing"

	"github.com/hanwen/go-fuse/v2/internal/testutil"
	"golang.org/x/sync/errgroup"
)

func BenchmarkGoFuseRead(b *testing.B) {
	fs := &readFS{}
	wd, clean := setupFs(fs, b.N)
	defer clean()

	jobs := 32
	blockSize := 64 * 1024

	cmds := make([]*exec.Cmd, jobs)

	for i := 0; i < jobs; i++ {
		cmds[i] = exec.Command("dd",
			fmt.Sprintf("if=%s/foo.txt", wd),
			"iflag=direct",
			"of=/dev/null",
			fmt.Sprintf("bs=%d", blockSize),
			fmt.Sprintf("count=%d", b.N))
		if testutil.VerboseTest() {
			cmds[i].Stdout = os.Stdout
			cmds[i].Stderr = os.Stderr
		}
	}

	b.SetBytes(int64(jobs * blockSize))
	b.ReportAllocs()
	b.ResetTimer()

	var eg errgroup.Group

	for i := 0; i < jobs; i++ {
		i := i
		eg.Go(func() error {
			return cmds[i].Run()
		})
	}

	if err := eg.Wait(); err != nil {
		b.Fatalf("dd failed: %v", err)
	}

	b.StopTimer()
}