Commit 1cc3d953 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Benchmark: timing fixes.

Move timer out of inner loop.
parent 48305247
...@@ -17,41 +17,41 @@ func BulkStat(parallelism int, files []string) float64 { ...@@ -17,41 +17,41 @@ func BulkStat(parallelism int, files []string) float64 {
todo := make(chan string, len(files)) todo := make(chan string, len(files))
dts := make(chan time.Duration, parallelism) dts := make(chan time.Duration, parallelism)
allStart := time.Now()
fmt.Printf("Statting %d files with %d threads\n", len(files), parallelism) fmt.Printf("Statting %d files with %d threads\n", len(files), parallelism)
for i := 0; i < parallelism; i++ { for i := 0; i < parallelism; i++ {
go func() { go func() {
t := time.Now()
for { for {
fn := <-todo fn := <-todo
if fn == "" { if fn == "" {
break break
} }
t := time.Now()
_, err := os.Lstat(fn) _, err := os.Lstat(fn)
if err != nil { if err != nil {
log.Fatal("All stats should succeed:", err) log.Fatal("All stats should succeed:", err)
} }
dts <- time.Now().Sub(t)
} }
dts <- time.Now().Sub(t)
}() }()
} }
allStart := time.Now()
for _, v := range files { for _, v := range files {
todo <- v todo <- v
} }
close(todo)
total := 0.0 total := 0.0
for i := 0; i < len(files); i++ { for i := 0; i < parallelism; i++ {
total += (<-dts).Seconds() * 1e-3 total += float64(<-dts) / float64(time.Millisecond)
} }
allEnd := time.Now() allDt := time.Now().Sub(allStart)
avg := total / float64(len(files)) avg := total / float64(len(files))
fmt.Printf("Elapsed: %f sec. Average stat %f ms\n", fmt.Printf("Elapsed: %f sec. Average stat %f ms\n",
allEnd.Sub(allStart).Seconds(), avg) allDt.Seconds(), avg)
return avg return avg
} }
......
...@@ -254,8 +254,8 @@ func BenchmarkCFuseThreadedStat(b *testing.B) { ...@@ -254,8 +254,8 @@ func BenchmarkCFuseThreadedStat(b *testing.B) {
} }
// Wait for the daemon to mount. // Wait for the daemon to mount.
time.Sleep(0.2e9) time.Sleep(200 * time.Millisecond)
ttl := 1.0 ttl := time.Second
log.Println("N = ", b.N) log.Println("N = ", b.N)
threads := runtime.GOMAXPROCS(0) threads := runtime.GOMAXPROCS(0)
results := TestingBOnePass(b, threads, time.Duration((ttl*12)/10), lines) results := TestingBOnePass(b, threads, time.Duration((ttl*12)/10), lines)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment