...
1 package main
2
3 import (
4 "fmt"
5 "golang.conradwood.net/go-easyops/utils"
6 "time"
7 )
8
9 func test_speed(name string, f func()) {
10
11 started := time.Now()
12 p := &utils.ProgressReporter{}
13 fmt.Printf("%s() speed:\n", name)
14 total := 0.0
15 ct := 0
16 for {
17 s1 := time.Now()
18 f()
19 total = total + time.Since(s1).Seconds()
20 ct++
21 p.Add(1)
22 p.Print()
23 if time.Since(started) > time.Duration(5)*time.Second {
24 break
25 }
26 }
27 avg := total / float64(ct)
28 fmt.Printf("Average speed of %s: %0.2fs\n", name, avg)
29 }
30
View as plain text