From bf00c9a461b07bafa79d767443d3646e83b5494d Mon Sep 17 00:00:00 2001 From: Paul Zabelin Date: Tue, 12 Mar 2019 03:16:43 -0700 Subject: [PATCH] add performance test to show bit cast init is faster --- .../project.pbxproj | 4 + ...1BF313F0-F809-434C-A147-7A5A9A911F00.plist | 32 ++++++ ...E9E0D678-741E-4B5A-BADA-15C171B67C91.plist | 32 ++++++ ...F73F58F2-54FD-4B61-BE11-7BFBBD73F8F3.plist | 32 ++++++ .../Info.plist | 102 ++++++++++++++++++ Example/Specs/PerformanceTest.swift | 41 +++++++ 6 files changed, 243 insertions(+) create mode 100644 Example/PerspectiveTransform.xcodeproj/xcshareddata/xcbaselines/4B74DB33203BD9C70030F41B.xcbaseline/1BF313F0-F809-434C-A147-7A5A9A911F00.plist create mode 100644 Example/PerspectiveTransform.xcodeproj/xcshareddata/xcbaselines/4B74DB33203BD9C70030F41B.xcbaseline/E9E0D678-741E-4B5A-BADA-15C171B67C91.plist create mode 100644 Example/PerspectiveTransform.xcodeproj/xcshareddata/xcbaselines/4B74DB33203BD9C70030F41B.xcbaseline/F73F58F2-54FD-4B61-BE11-7BFBBD73F8F3.plist create mode 100644 Example/PerspectiveTransform.xcodeproj/xcshareddata/xcbaselines/4B74DB33203BD9C70030F41B.xcbaseline/Info.plist create mode 100644 Example/Specs/PerformanceTest.swift diff --git a/Example/PerspectiveTransform.xcodeproj/project.pbxproj b/Example/PerspectiveTransform.xcodeproj/project.pbxproj index 7a457dd..5661ba5 100644 --- a/Example/PerspectiveTransform.xcodeproj/project.pbxproj +++ b/Example/PerspectiveTransform.xcodeproj/project.pbxproj @@ -35,6 +35,7 @@ 4BA7B1521C816DCE00933779 /* container.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 4B2D2E881C7C2E620045FD11 /* container.jpg */; }; 4BA7B1531C816DCE00933779 /* sky.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 4B2D2E8C1C7C323D0045FD11 /* sky.jpg */; }; 4BCA955F2237A7CE0091E312 /* CATransform3D+MatrixSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BCA955E2237A7CE0091E312 /* CATransform3D+MatrixSpec.swift */; }; + 4BCA95632237B9880091E312 /* PerformanceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BCA95622237B9880091E312 /* PerformanceTest.swift */; }; 4BD09EAE2046B05A006D2FA4 /* OpenCV_Spec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BD09EAD2046B05A006D2FA4 /* OpenCV_Spec.swift */; }; 4BD09EB220478E5C006D2FA4 /* PerspectiveTransformSpecHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BD09EB120478E5C006D2FA4 /* PerspectiveTransformSpecHelper.swift */; }; 4BD09EB320478E5C006D2FA4 /* PerspectiveTransformSpecHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BD09EB120478E5C006D2FA4 /* PerspectiveTransformSpecHelper.swift */; }; @@ -104,6 +105,7 @@ 4BB87C3B21F468CA00DABAED /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/LaunchScreen.xib; sourceTree = ""; }; 4BB87C3C21F468CA00DABAED /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = en.lproj/Main.storyboard; sourceTree = ""; }; 4BCA955E2237A7CE0091E312 /* CATransform3D+MatrixSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CATransform3D+MatrixSpec.swift"; sourceTree = ""; }; + 4BCA95622237B9880091E312 /* PerformanceTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PerformanceTest.swift; sourceTree = ""; }; 4BD09EAD2046B05A006D2FA4 /* OpenCV_Spec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenCV_Spec.swift; sourceTree = ""; }; 4BD09EB120478E5C006D2FA4 /* PerspectiveTransformSpecHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PerspectiveTransformSpecHelper.swift; sourceTree = ""; }; 4BDEE37220004185007214F1 /* PhotoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoViewController.swift; sourceTree = ""; }; @@ -182,6 +184,7 @@ 607FACEB1AFB9204008FA782 /* MatrixSpec.swift */, 4B58ECF61C79C3C200F1BC00 /* CATransform3Dfrom2DSpec.swift */, 4BCA955E2237A7CE0091E312 /* CATransform3D+MatrixSpec.swift */, + 4BCA95622237B9880091E312 /* PerformanceTest.swift */, 4B74DB2C203BAA1A0030F41B /* CALayerTransformSpec.swift */, 4BA3D17A1C771B2E0009B690 /* ProjectionSpec.swift */, 4B84138A201DD90D00D17FE2 /* PerspectiveSpec.swift */, @@ -691,6 +694,7 @@ 4BCA955F2237A7CE0091E312 /* CATransform3D+MatrixSpec.swift in Sources */, 4B74DB41203BDA070030F41B /* PerspectiveSpec.swift in Sources */, 4B74DB3E203BDA070030F41B /* CATransform3Dfrom2DSpec.swift in Sources */, + 4BCA95632237B9880091E312 /* PerformanceTest.swift in Sources */, 4B74DB45203BDA070030F41B /* VectorProjectionSpec.swift in Sources */, 4B74DB40203BDA070030F41B /* ProjectionSpec.swift in Sources */, 4B74DB3C203BDA070030F41B /* MatrixSpec.swift in Sources */, diff --git a/Example/PerspectiveTransform.xcodeproj/xcshareddata/xcbaselines/4B74DB33203BD9C70030F41B.xcbaseline/1BF313F0-F809-434C-A147-7A5A9A911F00.plist b/Example/PerspectiveTransform.xcodeproj/xcshareddata/xcbaselines/4B74DB33203BD9C70030F41B.xcbaseline/1BF313F0-F809-434C-A147-7A5A9A911F00.plist new file mode 100644 index 0000000..4cb3654 --- /dev/null +++ b/Example/PerspectiveTransform.xcodeproj/xcshareddata/xcbaselines/4B74DB33203BD9C70030F41B.xcbaseline/1BF313F0-F809-434C-A147-7A5A9A911F00.plist @@ -0,0 +1,32 @@ + + + + + classNames + + PerformanceTest + + testComparePerformance() + + com.apple.XCTPerformanceMetric_WallClockTime + + baselineAverage + 0.0113 + baselineIntegrationDisplayName + Local Baseline + + + testPerformance() + + com.apple.XCTPerformanceMetric_WallClockTime + + baselineAverage + 0.00583 + baselineIntegrationDisplayName + Local Baseline + + + + + + diff --git a/Example/PerspectiveTransform.xcodeproj/xcshareddata/xcbaselines/4B74DB33203BD9C70030F41B.xcbaseline/E9E0D678-741E-4B5A-BADA-15C171B67C91.plist b/Example/PerspectiveTransform.xcodeproj/xcshareddata/xcbaselines/4B74DB33203BD9C70030F41B.xcbaseline/E9E0D678-741E-4B5A-BADA-15C171B67C91.plist new file mode 100644 index 0000000..ab815ba --- /dev/null +++ b/Example/PerspectiveTransform.xcodeproj/xcshareddata/xcbaselines/4B74DB33203BD9C70030F41B.xcbaseline/E9E0D678-741E-4B5A-BADA-15C171B67C91.plist @@ -0,0 +1,32 @@ + + + + + classNames + + PerformanceTest + + testInitUsingBitcast() + + com.apple.XCTPerformanceMetric_WallClockTime + + baselineAverage + 0.0045609 + baselineIntegrationDisplayName + Local Baseline + + + testInitUsingDesignatedInitializer() + + com.apple.XCTPerformanceMetric_WallClockTime + + baselineAverage + 0.016586 + baselineIntegrationDisplayName + Local Baseline + + + + + + diff --git a/Example/PerspectiveTransform.xcodeproj/xcshareddata/xcbaselines/4B74DB33203BD9C70030F41B.xcbaseline/F73F58F2-54FD-4B61-BE11-7BFBBD73F8F3.plist b/Example/PerspectiveTransform.xcodeproj/xcshareddata/xcbaselines/4B74DB33203BD9C70030F41B.xcbaseline/F73F58F2-54FD-4B61-BE11-7BFBBD73F8F3.plist new file mode 100644 index 0000000..808e817 --- /dev/null +++ b/Example/PerspectiveTransform.xcodeproj/xcshareddata/xcbaselines/4B74DB33203BD9C70030F41B.xcbaseline/F73F58F2-54FD-4B61-BE11-7BFBBD73F8F3.plist @@ -0,0 +1,32 @@ + + + + + classNames + + PerformanceTest + + testInitUsingBitcast() + + com.apple.XCTPerformanceMetric_WallClockTime + + baselineAverage + 0.0029019 + baselineIntegrationDisplayName + Local Baseline + + + testInitUsingDesignatedInitializer() + + com.apple.XCTPerformanceMetric_WallClockTime + + baselineAverage + 0.01429 + baselineIntegrationDisplayName + Local Baseline + + + + + + diff --git a/Example/PerspectiveTransform.xcodeproj/xcshareddata/xcbaselines/4B74DB33203BD9C70030F41B.xcbaseline/Info.plist b/Example/PerspectiveTransform.xcodeproj/xcshareddata/xcbaselines/4B74DB33203BD9C70030F41B.xcbaseline/Info.plist new file mode 100644 index 0000000..dbb5b6f --- /dev/null +++ b/Example/PerspectiveTransform.xcodeproj/xcshareddata/xcbaselines/4B74DB33203BD9C70030F41B.xcbaseline/Info.plist @@ -0,0 +1,102 @@ + + + + + runDestinationsByUUID + + 1BF313F0-F809-434C-A147-7A5A9A911F00 + + localComputer + + busSpeedInMHz + 100 + cpuCount + 1 + cpuKind + Intel Core i7 + cpuSpeedInMHz + 4000 + logicalCPUCoresPerPackage + 8 + modelCode + iMac15,1 + physicalCPUCoresPerPackage + 4 + platformIdentifier + com.apple.platform.macosx + + targetArchitecture + x86_64 + targetDevice + + modelCode + iPhone11,8 + platformIdentifier + com.apple.platform.iphonesimulator + + + E9E0D678-741E-4B5A-BADA-15C171B67C91 + + localComputer + + busSpeedInMHz + 100 + cpuCount + 1 + cpuKind + Intel Core i7 + cpuSpeedInMHz + 4000 + logicalCPUCoresPerPackage + 8 + modelCode + iMac15,1 + physicalCPUCoresPerPackage + 4 + platformIdentifier + com.apple.platform.macosx + + targetArchitecture + x86_64 + targetDevice + + modelCode + iPad8,5 + platformIdentifier + com.apple.platform.iphonesimulator + + + F73F58F2-54FD-4B61-BE11-7BFBBD73F8F3 + + localComputer + + busSpeedInMHz + 100 + cpuCount + 1 + cpuKind + Intel Core i7 + cpuSpeedInMHz + 4000 + logicalCPUCoresPerPackage + 8 + modelCode + iMac15,1 + physicalCPUCoresPerPackage + 4 + platformIdentifier + com.apple.platform.macosx + + targetArchitecture + x86_64 + targetDevice + + modelCode + iPad6,12 + platformIdentifier + com.apple.platform.iphonesimulator + + + + + diff --git a/Example/Specs/PerformanceTest.swift b/Example/Specs/PerformanceTest.swift new file mode 100644 index 0000000..7480b22 --- /dev/null +++ b/Example/Specs/PerformanceTest.swift @@ -0,0 +1,41 @@ +// +// PerformanceTest.swift +// Framework Unit Specs +// +// Created by Paul Zabelin on 3/12/19. +// Copyright © 2019 CocoaPods. All rights reserved. +// + +import XCTest +import simd +@testable import PerspectiveTransform + +class PerformanceTest: XCTestCase { + let m4x4 = double4x4((1...4).map { row in + double4((1...4).map {Double(10 * row + $0)}) + }) + let iterations = 100000 + + /// Shows that bitcast is 2-4 times faster + func testInitUsingBitcast() { + measure { + for _ in (0...iterations) { + _ = CATransform3D(m4x4) + } + } + } + + /// Shows that designated init is slower + func testInitUsingDesignatedInitializer() { + measure { + for _ in (0...iterations) { + _ = CATransform3D( + m11: CGFloat(m4x4[0, 0]), m12: CGFloat(m4x4[0, 1]), m13: CGFloat(m4x4[0, 2]), m14: CGFloat(m4x4[0, 3]), + m21: CGFloat(m4x4[1, 0]), m22: CGFloat(m4x4[1, 1]), m23: CGFloat(m4x4[1, 2]), m24: CGFloat(m4x4[1, 3]), + m31: CGFloat(m4x4[2, 0]), m32: CGFloat(m4x4[2, 1]), m33: CGFloat(m4x4[2, 2]), m34: CGFloat(m4x4[2, 3]), + m41: CGFloat(m4x4[3, 0]), m42: CGFloat(m4x4[3, 1]), m43: CGFloat(m4x4[3, 2]), m44: CGFloat(m4x4[3, 3]) + ) + } + } + } +}