2018-01-24 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / go.test / test / mapnan.go
blobf081cab01d4b3a522b11c6112de38bc524fe2861
1 // +build darwin linux
2 // run
4 // Copyright 2013 The Go Authors. All rights reserved.
5 // Use of this source code is governed by a BSD-style
6 // license that can be found in the LICENSE file.
8 // Test that NaNs in maps don't go quadratic.
10 package main
12 import (
13 "fmt"
14 "math"
15 "time"
18 func main() {
20 // Test that NaNs in maps don't go quadratic.
21 t := func(n int) time.Duration {
22 t1 := time.Now()
23 m := map[float64]int{}
24 nan := math.NaN()
25 for i := 0; i < n; i++ {
26 m[nan] = 1
28 if len(m) != n {
29 panic("wrong size map after nan insertion")
31 return time.Since(t1)
34 // Depending on the machine and OS, this test might be too fast
35 // to measure with accurate enough granularity. On failure,
36 // make it run longer, hoping that the timing granularity
37 // is eventually sufficient.
39 n := 30000 // ~8ms user time on a Mid 2011 MacBook Air (1.8 GHz Core i7)
40 fails := 0
41 for {
42 t1 := t(n)
43 t2 := t(2 * n)
44 // should be 2x (linear); allow up to 3x
45 if t2 < 3*t1 {
46 return
48 fails++
49 if fails == 6 {
50 panic(fmt.Sprintf("too slow: %d inserts: %v; %d inserts: %v\n", n, t1, 2*n, t2))
52 if fails < 4 {
53 n *= 2