diff --git a/Package.swift b/Package.swift index 67842e7..0996cec 100644 --- a/Package.swift +++ b/Package.swift @@ -33,6 +33,7 @@ let package = Package( swiftSettings: [ .define("NO_OBJC_BRIDGE") ] ), .testTarget(name: "VucktTests", dependencies: ["Vuckt"], path: "Tests/", + sources: [ "VucktTests.swift", "VucktPerformanceTests.swift" ], swiftSettings: [ .define("NO_OBJC_BRIDGE") ] ), ], diff --git a/Tests/VucktCPerformanceTests.m b/Tests/VucktCPerformanceTests.m new file mode 100644 index 0000000..c773d34 --- /dev/null +++ b/Tests/VucktCPerformanceTests.m @@ -0,0 +1,72 @@ +// +// VucktCTests.m +// Vuckt +// +// Created by Cap'n Slipp on 5/13/20. +// + +#import +#import + + + +float randomFloatFromNegOneToPosOne() { + float randomFloat = (float)(arc4random() % ((uint32_t)RAND_MAX + 1)) / RAND_MAX; + return randomFloat * 2.0 - 1.0; +} + +static const int kIterationCount = 1000000; + + + +@interface VucktCTests : XCTestCase +@end + + +@implementation VucktCTests + +- (void)setUp { +} + +- (void)tearDown { +} + +- (void)testSimdFloat3Performance +{ + simd_float3 *testSetA = calloc(kIterationCount, sizeof(simd_float3)); + simd_float3 *testSetB = calloc(kIterationCount, sizeof(simd_float3)); + for (int i = 0; i < 1000000; ++i) { + float value = (float)i; + testSetA[i] = (simd_float3){ + value + (0 + randomFloatFromNegOneToPosOne()), + value - (500 + randomFloatFromNegOneToPosOne()), + value * (2.5 + randomFloatFromNegOneToPosOne()) + }; + testSetB[i] = (simd_float3){ + value + (500 + randomFloatFromNegOneToPosOne()), + -value * (10.0 + randomFloatFromNegOneToPosOne()), + value / (2.0 + randomFloatFromNegOneToPosOne()) + }; + } + + [self measureBlock:^{ + for (int i = 0; i < kIterationCount; ++i) { + simd_float3 result; + result = testSetA[i] + testSetB[i]; + result = testSetA[i] - testSetB[i]; + result = testSetA[i] * testSetB[i]; + result = testSetA[i] / testSetB[i]; + (void)result; + bool resultB; + resultB = simd_all(testSetA[i] < testSetB[i]); + resultB = simd_all(testSetA[i] <= testSetB[i]); + resultB = simd_all(testSetA[i] == testSetB[i]); + (void)resultB; + } + }]; + + free(testSetA); + free(testSetB); +} + +@end diff --git a/Tests/VucktPerformanceTests.swift b/Tests/VucktPerformanceTests.swift new file mode 100644 index 0000000..05d919b --- /dev/null +++ b/Tests/VucktPerformanceTests.swift @@ -0,0 +1,129 @@ +// Vuckt +// @author: Slipp Douglas Thompson +// @license: Public Domain per The Unlicense. See accompanying LICENSE file or . + +import XCTest +import Vuckt +import simd +import SceneKit + + + +class VucktPerformanceTests : XCTestCase +{ + static let iterationCount = 1_000_000 + + + override func setUp() + { + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDown() + { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + + func testFloat3Performance() + { + var testSetA:[Float3] = [] + var testSetB:[Float3] = [] + (0.. Float { + let randomFloat = Float(arc4random() % (UInt32(RAND_MAX) + 1)) / Float(RAND_MAX) + return randomFloat * 2.0 - 1.0; + } + + func testSIMDFloat3Performance() + { + var testSetA:[simd.float3] = [] + var testSetB:[simd.float3] = [] + (0.. - - - -