Skip to content
This repository has been archived by the owner on Aug 25, 2021. It is now read-only.

Commit

Permalink
Using proper P values
Browse files Browse the repository at this point in the history
  • Loading branch information
tscs37 committed Apr 1, 2018
1 parent 9094c84 commit df114e9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions bench.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ func bench(dnsServer, target string, measurements uint16, cb ProgressCallback) (
}

sort.Slice(ttls, func(i, j int) bool {
// sort worst first
return ttls[i].Nanoseconds() > ttls[j].Nanoseconds()
return ttls[i].Nanoseconds() < ttls[j].Nanoseconds()
})

var avg int64
Expand All @@ -99,16 +98,17 @@ func bench(dnsServer, target string, measurements uint16, cb ProgressCallback) (
}

func Px(sl []time.Duration, p float64) time.Duration {
var res int64
var res int64 = 0
numR := int64(
math.Min(
math.Ceil(p*float64(len(sl))),
float64(len(sl)),
),
)
for i := int64(0); i < numR && i < int64(len(sl)); i++ {
res += sl[i].Nanoseconds()
if res < sl[i].Nanoseconds() {
res = sl[i].Nanoseconds()
}
}
res /= numR
return time.Duration(res) * time.Nanosecond
}

0 comments on commit df114e9

Please sign in to comment.