Skip to content

Commit

Permalink
performance benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderTar committed Mar 15, 2017
1 parent 07a7fcd commit 4ba614d
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Example/LASwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
D6AB38F19319980B12634450 /* Pods_LASwift_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B9BA33C94DB81BD751A7C512 /* Pods_LASwift_Tests.framework */; };
FA4AC4081E5E3EF000D5F51F /* VectorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA4AC4071E5E3EF000D5F51F /* VectorTests.swift */; };
FA4AC40E1E6614EC00D5F51F /* MatrixTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA4AC40D1E6614EC00D5F51F /* MatrixTests.swift */; };
FAD2257E1E7925C40012219D /* PerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAD2257D1E7925C40012219D /* PerformanceTests.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -23,6 +24,7 @@
B9BA33C94DB81BD751A7C512 /* Pods_LASwift_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LASwift_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
FA4AC4071E5E3EF000D5F51F /* VectorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VectorTests.swift; sourceTree = "<group>"; };
FA4AC40D1E6614EC00D5F51F /* MatrixTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MatrixTests.swift; sourceTree = "<group>"; };
FAD2257D1E7925C40012219D /* PerformanceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PerformanceTests.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -71,6 +73,7 @@
FA4AC4071E5E3EF000D5F51F /* VectorTests.swift */,
FA4AC40D1E6614EC00D5F51F /* MatrixTests.swift */,
607FACE91AFB9204008FA782 /* Supporting Files */,
FAD2257D1E7925C40012219D /* PerformanceTests.swift */,
);
path = Tests;
sourceTree = "<group>";
Expand Down Expand Up @@ -224,6 +227,7 @@
files = (
FA4AC4081E5E3EF000D5F51F /* VectorTests.swift in Sources */,
FA4AC40E1E6614EC00D5F51F /* MatrixTests.swift in Sources */,
FAD2257E1E7925C40012219D /* PerformanceTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
90 changes: 90 additions & 0 deletions Example/Tests/PerformanceTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// PerformanceTests.swift
// LASwift
//
// Created by Alexander Taraymovich on 15/03/2017.
// Copyright © 2017 CocoaPods. All rights reserved.
//

import LASwift
import XCTest

class PerformanceTests: XCTestCase {
let a = rand(1000, 1000)
let b = rand(1000, 1000)
let x = rand(1000000)
let y = rand(1000000)

func testRandomMatrix() {
measure {
_ = rand(1000, 1000)
}
}

func testInvert() {
measure {
_ = inv(self.a)
}
}

func testCholesky() {
let aTa = transpose(a) * a
measure {
_ = chol(aTa)
}
}

func testDot() {
measure {
_ = self.x * self.y
}
}

func testTranspose() {
measure {
_ = transpose(self.a)
}
}

func testMultiply() {
measure {
_ = self.a * self.b
}
}

func testSigmoid() {
measure {
_ = 1 ./ (1 + exp(-self.a))
}
}

func testReLU() {
measure {
_ = thr(self.a, 0)
}
}

func testSumByRows() {
measure {
_ = sum(self.a, .Row)
}
}

func testSumByColumns() {
measure {
_ = sum(self.a, .Column)
}
}

func testMaxIndicesByRows() {
measure {
_ = maxi(self.a, .Row)
}
}

func testMaxIndicesByColumns() {
measure {
_ = maxi(self.a, .Column)
}
}
}
4 changes: 2 additions & 2 deletions Sources/MatrixAlgebra.swift
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ public func chol(_ A: Matrix) -> Matrix {

U = transpose(U)

_ = (0..<A.rows).map { i in
_ = (0..<i).map { j in
for i in (0..<A.rows) {
for j in (0..<i) {
U[i, j] = 0.0
}
}
Expand Down

0 comments on commit 4ba614d

Please sign in to comment.