-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Created performance tests to compare Vuckt's `Float3` performance to Swift `simd.float`'s to `GLKVector3` to C/Obj-C `simd_float3`. * Added new `VucktPerformanceTests.swift` and `VucktCPerformanceTests.m` to Xcode project & SPM package. * Minor: Removed old placeholder `testPerformanceExample()`.
- Loading branch information
Showing
6 changed files
with
223 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// | ||
// VucktCTests.m | ||
// Vuckt | ||
// | ||
// Created by Cap'n Slipp on 5/13/20. | ||
// | ||
|
||
#import <XCTest/XCTest.h> | ||
#import <simd/simd.h> | ||
|
||
|
||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
// Vuckt | ||
// @author: Slipp Douglas Thompson | ||
// @license: Public Domain per The Unlicense. See accompanying LICENSE file or <http://unlicense.org/>. | ||
|
||
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..<Self.iterationCount).forEach{ i in | ||
let value = Float(i) | ||
testSetA.append(Float3( | ||
x: value, | ||
y: value - 500, | ||
z: value * 2.5 | ||
)) | ||
testSetB.append(Float3( | ||
x: value + 500, | ||
y: -value * 10.0, | ||
z: value / 2.0 | ||
)) | ||
} | ||
|
||
|
||
self.measure { | ||
(0..<Self.iterationCount).forEach{ i in | ||
_ = testSetA[i] + testSetB[i] | ||
_ = testSetA[i] - testSetB[i] | ||
_ = testSetA[i] * testSetB[i] | ||
_ = testSetA[i] / testSetB[i] | ||
_ = testSetA[i] < testSetB[i] | ||
_ = testSetA[i] <= testSetB[i] | ||
_ = testSetA[i] == testSetB[i] | ||
} | ||
} | ||
} | ||
|
||
private func randomFloatFromNegOneToPosOne() -> 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..<Self.iterationCount).forEach{ i in | ||
let value = Float(i) | ||
testSetA.append(simd.float3( | ||
x: value + (0 + randomFloatFromNegOneToPosOne()), | ||
y: value - (500 + randomFloatFromNegOneToPosOne()), | ||
z: value * (2.5 + randomFloatFromNegOneToPosOne()) | ||
)) | ||
testSetB.append(simd.float3( | ||
x: value + (500 + randomFloatFromNegOneToPosOne()), | ||
y: -value * (10.0 + randomFloatFromNegOneToPosOne()), | ||
z: value / (2.0 + randomFloatFromNegOneToPosOne()) | ||
)) | ||
} | ||
|
||
|
||
self.measure { | ||
(0..<Self.iterationCount).forEach{ i in | ||
_ = testSetA[i] + testSetB[i] | ||
_ = testSetA[i] - testSetB[i] | ||
_ = testSetA[i] * testSetB[i] | ||
_ = testSetA[i] / testSetB[i] | ||
_ = all(testSetA[i] .< testSetB[i]) | ||
_ = all(testSetA[i] .<= testSetB[i]) | ||
_ = testSetA[i] == testSetB[i] | ||
} | ||
} | ||
} | ||
|
||
func testGLKVector3Performance() | ||
{ | ||
var testSetA:[GLKVector3] = [] | ||
var testSetB:[GLKVector3] = [] | ||
(0..<Self.iterationCount).forEach{ i in | ||
let value = Float(i) | ||
testSetA.append(GLKVector3Make( | ||
value, | ||
value - 500, | ||
value * 2.5 | ||
)) | ||
testSetB.append(GLKVector3Make( | ||
value + 500, | ||
-value * 10.0, | ||
value / 2.0 | ||
)) | ||
} | ||
|
||
|
||
self.measure { | ||
(0..<Self.iterationCount).forEach{ i in | ||
_ = GLKVector3Add(testSetA[i], testSetB[i]) | ||
_ = GLKVector3Subtract(testSetA[i], testSetB[i]) | ||
_ = GLKVector3Multiply(testSetA[i], testSetB[i]) | ||
_ = GLKVector3Divide(testSetA[i], testSetB[i]) | ||
_ = GLKVector3AllGreaterThanVector3(testSetB[i], testSetA[i]) | ||
_ = GLKVector3AllGreaterThanOrEqualToVector3(testSetB[i], testSetA[i]) | ||
_ = GLKVector3AllEqualToVector3(testSetA[i], testSetB[i]) | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters