Skip to content

Commit

Permalink
mountinfo: add benchmark for unescape
Browse files Browse the repository at this point in the history
    go test -v -test.benchmem -count=10 -run ^$ -bench BenchmarkUnescape .
    go: downloading golang.org/x/sys v0.1.0
    goos: linux
    goarch: arm64
    pkg: github.com/moby/sys/mountinfo
    BenchmarkUnescape
    BenchmarkUnescape-10     1000000      1068 ns/op     640 B/op      31 allocs/op
    BenchmarkUnescape-10      992292      1082 ns/op     640 B/op      31 allocs/op
    BenchmarkUnescape-10     1000000      1050 ns/op     640 B/op      31 allocs/op
    BenchmarkUnescape-10     1000000      1038 ns/op     640 B/op      31 allocs/op
    BenchmarkUnescape-10     1000000      1034 ns/op     640 B/op      31 allocs/op
    BenchmarkUnescape-10     1000000      1045 ns/op     640 B/op      31 allocs/op
    BenchmarkUnescape-10     1000000      1071 ns/op     640 B/op      31 allocs/op
    BenchmarkUnescape-10     1000000      1033 ns/op     640 B/op      31 allocs/op
    BenchmarkUnescape-10     1000000      1032 ns/op     640 B/op      31 allocs/op
    BenchmarkUnescape-10     1000000      1070 ns/op     640 B/op      31 allocs/op
    PASS
    ok  github.com/moby/sys/mountinfo 10.653s

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah authored and kolyshkin committed Jul 26, 2024
1 parent 86870e7 commit 0015f62
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions mountinfo/mountinfo_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,3 +771,32 @@ func TestUnescape(t *testing.T) {
}
}
}

func BenchmarkUnescape(b *testing.B) {
testCases := []string{
"",
"/",
"/some/longer/path",
"/path\\040with\\040spaces",
"/path/with\\134backslash",
"/tab\\011in/path",
`/path/"with'quotes`,
`/path/"with'quotes,\040space,\011tab`,
`\12`,
`\134`,
`"'"'"'`,
`/\1345`,
`/\12x`,
`\0`,
`\x`,
"\\\\",
}

b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for x := 0; x < len(testCases); x++ {
_, _ = unescape(testCases[x])
}
}
}

0 comments on commit 0015f62

Please sign in to comment.