lib/fs: optimize Windows path checking/sanitizing
name old time/op new time/op delta WindowsInvalidFilenameValid-8 875ns ± 1% 150ns ± 1% -82.84% (p=0.000 n=9+9) WindowsInvalidFilenameNUL-8 276ns ± 4% 121ns ± 3% -56.26% (p=0.000 n=10+10) name old alloc/op new alloc/op delta WindowsInvalidFilenameValid-8 32.0B ± 0% 16.0B ± 0% -50.00% (p=0.000 n=10+10) WindowsInvalidFilenameNUL-8 32.0B ± 0% 19.0B ± 0% -40.62% (p=0.000 n=10+10) name old allocs/op new allocs/op delta WindowsInvalidFilenameValid-8 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.000 n=10+10) WindowsInvalidFilenameNUL-8 2.00 ± 0% 2.00 ± 0% ~ (all equal)
This commit is contained in:
@@ -117,3 +117,15 @@ func TestSanitizePathFuzz(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func benchmarkWindowsInvalidFilename(b *testing.B, name string) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
WindowsInvalidFilename(name)
|
||||
}
|
||||
}
|
||||
func BenchmarkWindowsInvalidFilenameValid(b *testing.B) {
|
||||
benchmarkWindowsInvalidFilename(b, "License.txt.gz")
|
||||
}
|
||||
func BenchmarkWindowsInvalidFilenameNUL(b *testing.B) {
|
||||
benchmarkWindowsInvalidFilename(b, "nul.txt.gz")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user