complex_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. package runtime_test
  5. import (
  6. "math/cmplx"
  7. "testing"
  8. )
  9. var result complex128
  10. func BenchmarkComplex128DivNormal(b *testing.B) {
  11. d := 15 + 2i
  12. n := 32 + 3i
  13. res := 0i
  14. for i := 0; i < b.N; i++ {
  15. n += 0.1i
  16. res += n / d
  17. }
  18. result = res
  19. }
  20. func BenchmarkComplex128DivNisNaN(b *testing.B) {
  21. d := cmplx.NaN()
  22. n := 32 + 3i
  23. res := 0i
  24. for i := 0; i < b.N; i++ {
  25. n += 0.1i
  26. res += n / d
  27. }
  28. result = res
  29. }
  30. func BenchmarkComplex128DivDisNaN(b *testing.B) {
  31. d := 15 + 2i
  32. n := cmplx.NaN()
  33. res := 0i
  34. for i := 0; i < b.N; i++ {
  35. d += 0.1i
  36. res += n / d
  37. }
  38. result = res
  39. }
  40. func BenchmarkComplex128DivNisInf(b *testing.B) {
  41. d := 15 + 2i
  42. n := cmplx.Inf()
  43. res := 0i
  44. for i := 0; i < b.N; i++ {
  45. d += 0.1i
  46. res += n / d
  47. }
  48. result = res
  49. }
  50. func BenchmarkComplex128DivDisInf(b *testing.B) {
  51. d := cmplx.Inf()
  52. n := 32 + 3i
  53. res := 0i
  54. for i := 0; i < b.N; i++ {
  55. n += 0.1i
  56. res += n / d
  57. }
  58. result = res
  59. }