diff --git a/Sources/_NumericsShims/include/_NumericsShims.h b/Sources/_NumericsShims/include/_NumericsShims.h index 4e1b40bf..47148dae 100644 --- a/Sources/_NumericsShims/include/_NumericsShims.h +++ b/Sources/_NumericsShims/include/_NumericsShims.h @@ -383,6 +383,10 @@ HEADER_SHIM long double libm_lgammal(long double x, int *signp) { #endif // MARK: - shims to import C complex operations for timing purposes +#if !defined _WIN32 +// Clang doesn't have support for complex arithmetic on Windows, so +// it doesn't make sense to benchmark against it (and these will +// fail to link if used there). typedef struct { double real; double imag; } CComplex; @@ -399,3 +403,5 @@ HEADER_SHIM CComplex libm_cmul(CComplex z, CComplex w) { double _Complex c = a*b; return (CComplex){ __real__ c, __imag__ c }; } + +#endif diff --git a/Tests/ComplexTests/ArithmeticBenchmarkTests.swift b/Tests/ComplexTests/ArithmeticBenchmarkTests.swift deleted file mode 100644 index 6b2d94d2..00000000 --- a/Tests/ComplexTests/ArithmeticBenchmarkTests.swift +++ /dev/null @@ -1,180 +0,0 @@ -//===--- ArithmeticBenchmarkTests.swift -----------------------*- swift -*-===// -// -// This source file is part of the Swift Numerics open source project -// -// Copyright (c) 2019 Apple Inc. and the Swift Numerics project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - -import XCTest -import ComplexModule - -// For CComplex and shims -import _NumericsShims - -extension Complex where RealType == Double { - @_transparent - init(_ other: CComplex) { - self = unsafeBitCast(other, to: Complex.self) - } - @_transparent - var ctype: CComplex { - unsafeBitCast(self, to: CComplex.self) - } -} - -let wellScaledDoubles: [Complex] = (0 ..< 1024).map { _ in - Complex(length: Double.random(in: 0.5 ..< 2.0), - phase: Double.random(in: -.pi ..< .pi)) -} - -let poorlyScaledDoubles: [Complex] = (0 ..< 1024).map { _ in - Complex( - length: Double(sign: .plus, - exponent: .random(in: -970 ... 1023), - significand: .random(in: 1 ..< 2)), - phase: Double.random(in: -.pi ..< .pi) - ) -} - -final class ArithmeticBenchmarkTests: XCTestCase { - - let iters = 1000 - - func testDivisionByConstant() { - let divisor = wellScaledDoubles[0] - var sum = Complex.zero - measure { - for _ in 0 ..< iters { - sum = wellScaledDoubles.reduce(into: sum) { $0 += $1 / divisor } - } - } - print(sum) - } - - func testReciprocal() { - let recip = wellScaledDoubles[0].reciprocal! - var sum = Complex.zero - measure { - for _ in 0 ..< iters { - sum = wellScaledDoubles.reduce(into: sum) { $0 += $1 * recip } - } - } - print(sum) - } - - func testDivisionByConstantC() { - let divisor = wellScaledDoubles[0].ctype - var sum = Complex.zero - measure { - for _ in 0 ..< iters { - sum = wellScaledDoubles.reduce(into: sum) { - $0 += Complex(libm_cdiv($1.ctype, divisor)) - } - } - } - print(sum) - } - - func testMultiplication() { - let multiplicand = wellScaledDoubles[0] - var sum = Complex.zero - measure { - for _ in 0 ..< iters { - sum = wellScaledDoubles.reduce(into: sum) { $0 += $1 * multiplicand } - } - } - print(sum) - } - - func testMultiplicationC() { - let multiplicand = wellScaledDoubles[0].ctype - var sum = Complex.zero - measure { - for _ in 0 ..< iters { - sum = wellScaledDoubles.reduce(into: sum) { - $0 += Complex(libm_cmul($1.ctype, multiplicand)) - } - } - } - print(sum) - } - - func testDivision() { - var sum = Complex.zero - measure { - for o in 0 ..< iters { - for i in 0 ..< 1024 { - sum += wellScaledDoubles[i] / wellScaledDoubles[(i &- o) & 1023] - } - } - } - print(sum) - } - - func testDivisionC() { - var sum = Complex.zero - measure { - for o in 0 ..< iters { - for i in 0 ..< 1024 { - sum += Complex(libm_cdiv(wellScaledDoubles[i].ctype, - wellScaledDoubles[(i &- o) & 1023].ctype)) - } - } - } - print(sum) - } - - func testDivisionPoorScaling() { - var sum = Complex.zero - measure { - for o in 0 ..< iters { - for i in 0 ..< 1024 { - sum += poorlyScaledDoubles[i] / poorlyScaledDoubles[(i &- o) & 1023] - } - } - } - print(sum) - } - - func testDivisionPoorScalingC() { - var sum = Complex.zero - measure { - for o in 0 ..< iters { - for i in 0 ..< 1024 { - sum += Complex(libm_cdiv(poorlyScaledDoubles[i].ctype, - poorlyScaledDoubles[(i &- o) & 1023].ctype)) - } - } - } - print(sum) - } - - func testMultiplicationPoorScaling() { - var sum = Complex.zero - measure { - for o in 0 ..< iters { - for i in 0 ..< 1024 { - sum += poorlyScaledDoubles[i] * poorlyScaledDoubles[(i &- o) & 1023] - } - } - } - print(sum) - } - - func testMultiplicationPoorScalingC() { - var sum = Complex.zero - measure { - for o in 0 ..< iters { - for i in 0 ..< 1024 { - sum += Complex(libm_cmul(poorlyScaledDoubles[i].ctype, - poorlyScaledDoubles[(i &- o) & 1023].ctype)) - } - } - } - print(sum) - } -}