mirror of
https://github.com/golang/go
synced 2024-10-14 11:53:56 +00:00
test/mapnan: use time.Now instead of syscall.Getrusage
Avoids a dependency on a somewhat nonstandard part of package syscall. R=golang-dev, dave, r CC=golang-dev https://golang.org/cl/15570046
This commit is contained in:
parent
c8ddfd9ad1
commit
08a5614597
|
@ -13,17 +13,13 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
"syscall"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
// Test that NaNs in maps don't go quadratic.
|
// Test that NaNs in maps don't go quadratic.
|
||||||
t := func(n int) time.Duration {
|
t := func(n int) time.Duration {
|
||||||
var u0 syscall.Rusage
|
t1 := time.Now()
|
||||||
if err := syscall.Getrusage(0, &u0); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
m := map[float64]int{}
|
m := map[float64]int{}
|
||||||
nan := math.NaN()
|
nan := math.NaN()
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
|
@ -32,11 +28,7 @@ func main() {
|
||||||
if len(m) != n {
|
if len(m) != n {
|
||||||
panic("wrong size map after nan insertion")
|
panic("wrong size map after nan insertion")
|
||||||
}
|
}
|
||||||
var u1 syscall.Rusage
|
return time.Since(t1)
|
||||||
if err := syscall.Getrusage(0, &u1); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return time.Duration(u1.Utime.Nano() - u0.Utime.Nano())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Depending on the machine and OS, this test might be too fast
|
// Depending on the machine and OS, this test might be too fast
|
||||||
|
|
Loading…
Reference in a new issue