-
Notifications
You must be signed in to change notification settings - Fork 86
/
PerformanceTests.swift
103 lines (92 loc) · 1.97 KB
/
PerformanceTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import XCTest
class PerformanceTests: XCTestCase {
func testCreateFromArrayRange() {
var a = [[Double]]()
for _ in 0..<1000 {
a.append([Double](repeating: Double.pi, count: 1000))
}
measure() {
for _ in 1...10 {
let _ = Matrix(a, range: 0..<1000)
}
}
}
func testTile() {
let v = Matrix.random(rows: 1, columns: 1000)
measure() {
for _ in 1...10 {
let _ = v.tile(2000)
}
}
}
func testCopyEntireMatrix() {
let M = Matrix.random(rows: 1000, columns: 1000)
measure() {
for _ in 1...10 {
let _ = M[rows: Array(0..<1000)]
}
}
}
func testSubscriptRowGetter() {
var M = Matrix.random(rows: 1000, columns: 1000)
measure() {
for _ in 1...10 {
for i in 0..<M.rows {
let _ = M[row: i]
}
}
}
}
func testSubscriptRowSetter() {
var M = Matrix.random(rows: 1000, columns: 1000)
let v = Matrix.random(rows: 1, columns: 1000)
measure() {
for _ in 1...10 {
for i in 0..<M.rows {
M[row: i] = v
}
}
}
}
func testSubscripColumnGetter() {
var M = Matrix.random(rows: 1000, columns: 1000)
measure() {
for _ in 1...10 {
for i in 0..<M.columns {
let _ = M[column: i]
}
}
}
}
func testSubscriptColumnSetter() {
var M = Matrix.random(rows: 1000, columns: 1000)
let v = Matrix.random(rows: 1000, columns: 1)
measure() {
for _ in 1...10 {
for i in 0..<M.columns {
M[column: i] = v
}
}
}
}
func testSqrt() {
let M = Matrix.random(rows: 1000, columns: 1000)
measure() {
for _ in 1...10 {
let _ = M.sqrt()
}
}
}
func testPow2() {
let M = Matrix.random(rows: 1000, columns: 1000)
measure() {
let _ = M.pow(2)
}
}
func testPow3() {
let M = Matrix.random(rows: 1000, columns: 1000)
measure() {
let _ = M.pow(3)
}
}
}