aboutsummaryrefslogtreecommitdiff
path: root/src/os/os_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/os/os_test.go')
-rw-r--r--src/os/os_test.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/os/os_test.go b/src/os/os_test.go
index be9fa91028..ef06ba28d1 100644
--- a/src/os/os_test.go
+++ b/src/os/os_test.go
@@ -296,6 +296,48 @@ func TestReaddir(t *testing.T) {
testReaddir(sysdir.name, sysdir.files, t)
}
+func benchmarkReaddirname(path string, b *testing.B) {
+ var nentries int
+ for i := 0; i < b.N; i++ {
+ f, err := Open(path)
+ if err != nil {
+ b.Fatalf("open %q failed: %v", path, err)
+ }
+ ns, err := f.Readdirnames(-1)
+ f.Close()
+ if err != nil {
+ b.Fatalf("readdirnames %q failed: %v", path, err)
+ }
+ nentries = len(ns)
+ }
+ b.Logf("benchmarkReaddirname %q: %d entries", path, nentries)
+}
+
+func benchmarkReaddir(path string, b *testing.B) {
+ var nentries int
+ for i := 0; i < b.N; i++ {
+ f, err := Open(path)
+ if err != nil {
+ b.Fatalf("open %q failed: %v", path, err)
+ }
+ fs, err := f.Readdir(-1)
+ f.Close()
+ if err != nil {
+ b.Fatalf("readdir %q failed: %v", path, err)
+ }
+ nentries = len(fs)
+ }
+ b.Logf("benchmarkReaddir %q: %d entries", path, nentries)
+}
+
+func BenchmarkReaddirname(b *testing.B) {
+ benchmarkReaddirname(".", b)
+}
+
+func BenchmarkReaddir(b *testing.B) {
+ benchmarkReaddir(".", b)
+}
+
// Read the directory one entry at a time.
func smallReaddirnames(file *File, length int, t *testing.T) []string {
names := make([]string, length)