Michael Chaten | 32c3a62 | 2012-04-21 13:24:41 +1000 | [diff] [blame] | 1 | // Copyright 2012 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package runtime_test |
| 6 | |
| 7 | import ( |
| 8 | "math/cmplx" |
| 9 | "testing" |
| 10 | ) |
| 11 | |
| 12 | var result complex128 |
| 13 | |
| 14 | func BenchmarkComplex128DivNormal(b *testing.B) { |
| 15 | d := 15 + 2i |
| 16 | n := 32 + 3i |
Shenghou Ma | aa45e52 | 2012-05-11 03:09:14 +0800 | [diff] [blame] | 17 | res := 0i |
Michael Chaten | 32c3a62 | 2012-04-21 13:24:41 +1000 | [diff] [blame] | 18 | for i := 0; i < b.N; i++ { |
Shenghou Ma | aa45e52 | 2012-05-11 03:09:14 +0800 | [diff] [blame] | 19 | n += 0.1i |
| 20 | res += n / d |
Michael Chaten | 32c3a62 | 2012-04-21 13:24:41 +1000 | [diff] [blame] | 21 | } |
Shenghou Ma | aa45e52 | 2012-05-11 03:09:14 +0800 | [diff] [blame] | 22 | result = res |
Michael Chaten | 32c3a62 | 2012-04-21 13:24:41 +1000 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | func BenchmarkComplex128DivNisNaN(b *testing.B) { |
| 26 | d := cmplx.NaN() |
| 27 | n := 32 + 3i |
Shenghou Ma | aa45e52 | 2012-05-11 03:09:14 +0800 | [diff] [blame] | 28 | res := 0i |
Michael Chaten | 32c3a62 | 2012-04-21 13:24:41 +1000 | [diff] [blame] | 29 | for i := 0; i < b.N; i++ { |
Shenghou Ma | aa45e52 | 2012-05-11 03:09:14 +0800 | [diff] [blame] | 30 | n += 0.1i |
| 31 | res += n / d |
Michael Chaten | 32c3a62 | 2012-04-21 13:24:41 +1000 | [diff] [blame] | 32 | } |
Shenghou Ma | aa45e52 | 2012-05-11 03:09:14 +0800 | [diff] [blame] | 33 | result = res |
Michael Chaten | 32c3a62 | 2012-04-21 13:24:41 +1000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | func BenchmarkComplex128DivDisNaN(b *testing.B) { |
| 37 | d := 15 + 2i |
| 38 | n := cmplx.NaN() |
Shenghou Ma | aa45e52 | 2012-05-11 03:09:14 +0800 | [diff] [blame] | 39 | res := 0i |
Michael Chaten | 32c3a62 | 2012-04-21 13:24:41 +1000 | [diff] [blame] | 40 | for i := 0; i < b.N; i++ { |
Shenghou Ma | aa45e52 | 2012-05-11 03:09:14 +0800 | [diff] [blame] | 41 | d += 0.1i |
| 42 | res += n / d |
Michael Chaten | 32c3a62 | 2012-04-21 13:24:41 +1000 | [diff] [blame] | 43 | } |
Shenghou Ma | aa45e52 | 2012-05-11 03:09:14 +0800 | [diff] [blame] | 44 | result = res |
Michael Chaten | 32c3a62 | 2012-04-21 13:24:41 +1000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | func BenchmarkComplex128DivNisInf(b *testing.B) { |
| 48 | d := 15 + 2i |
| 49 | n := cmplx.Inf() |
Shenghou Ma | aa45e52 | 2012-05-11 03:09:14 +0800 | [diff] [blame] | 50 | res := 0i |
Michael Chaten | 32c3a62 | 2012-04-21 13:24:41 +1000 | [diff] [blame] | 51 | for i := 0; i < b.N; i++ { |
Shenghou Ma | aa45e52 | 2012-05-11 03:09:14 +0800 | [diff] [blame] | 52 | d += 0.1i |
| 53 | res += n / d |
Michael Chaten | 32c3a62 | 2012-04-21 13:24:41 +1000 | [diff] [blame] | 54 | } |
Shenghou Ma | aa45e52 | 2012-05-11 03:09:14 +0800 | [diff] [blame] | 55 | result = res |
Michael Chaten | 32c3a62 | 2012-04-21 13:24:41 +1000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | func BenchmarkComplex128DivDisInf(b *testing.B) { |
| 59 | d := cmplx.Inf() |
| 60 | n := 32 + 3i |
Shenghou Ma | aa45e52 | 2012-05-11 03:09:14 +0800 | [diff] [blame] | 61 | res := 0i |
Michael Chaten | 32c3a62 | 2012-04-21 13:24:41 +1000 | [diff] [blame] | 62 | for i := 0; i < b.N; i++ { |
Shenghou Ma | aa45e52 | 2012-05-11 03:09:14 +0800 | [diff] [blame] | 63 | n += 0.1i |
| 64 | res += n / d |
Michael Chaten | 32c3a62 | 2012-04-21 13:24:41 +1000 | [diff] [blame] | 65 | } |
Shenghou Ma | aa45e52 | 2012-05-11 03:09:14 +0800 | [diff] [blame] | 66 | result = res |
Michael Chaten | 32c3a62 | 2012-04-21 13:24:41 +1000 | [diff] [blame] | 67 | } |