Skip to content

Commit

Permalink
fix: add WaitGroup to accurately measure elapsed time of benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredfolkins authored and jdef committed Feb 18, 2019
1 parent f3dae7c commit 65cb06f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tools/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"time"
"sync"

"github.com/miekg/dns"
)
Expand Down Expand Up @@ -32,14 +33,19 @@ func query(dom string) {
}

func main() {
wg := &sync.WaitGroup{}
start := time.Now()

cnt := 10000

for i := 0; i < cnt; i++ {
go query("bob.mesos")
wg.Add(1)
go func() {
query("bob.mesos")
wg.Done()
}()
}

wg.Wait()
elapsed := time.Since(start)
log.Printf("benching took %s", elapsed)
log.Printf("doing %d/%v rps", cnt, elapsed)
Expand Down

0 comments on commit 65cb06f

Please sign in to comment.