@@ -24,45 +24,47 @@ import XCTest
24
24
@testable import SwiftPriorityQueue
25
25
26
26
class SwiftPriorityQueuePerformanceTests : XCTestCase {
27
-
28
- func testBuildPerformance( ) {
29
- let input : [ Int ] = Array ( ( 0 ..< 100000 ) )
30
- measure {
27
+
28
+ func testBuildPerformance( ) {
29
+ let input : [ Int ] = Array ( ( 0 ..< 100000 ) )
30
+ measure {
31
31
let _: PriorityQueue < Int > = PriorityQueue ( ascending: true , startingValues: input)
32
- }
33
- }
34
-
35
- func testPopPerformance( ) {
36
- var pq = PriorityQueue ( ascending: true , startingValues: Array ( 0 ..< 100000 ) )
32
+ }
33
+ }
34
+
35
+ func testPopPerformance( ) {
36
+ let original = PriorityQueue ( ascending: true , startingValues: Array ( 0 ..< 100000 ) )
37
+ measure {
38
+ var pq = original
39
+ for _ in 0 ..< 100000 {
40
+ let _ = pq. pop ( )
41
+ }
42
+ }
43
+ }
44
+
45
+ func testPushPerformance( ) {
37
46
measure {
38
- for _ in 0 ..< 100000 {
39
- let _ = pq. pop ( )
40
- }
41
- }
42
- }
43
-
44
- func testPushPerformance( ) {
45
- var pq = PriorityQueue < Int > ( ascending: true , startingValues: [ ] )
46
- measure {
47
- for i in 0 ..< 100000 {
48
- pq. push ( i)
49
- }
50
- }
51
- }
52
-
53
- func testRemovePerformance( ) {
54
- var pq = PriorityQueue ( ascending: true , startingValues: Array ( 0 ..< 10000 ) )
55
- measure {
47
+ for i in 0 ..< 100000 {
48
+ var pq = PriorityQueue < Int > ( ascending: true , startingValues: [ ] )
49
+ pq. push ( i)
50
+ }
51
+ }
52
+ }
53
+
54
+ func testRemovePerformance( ) {
55
+ let original = PriorityQueue ( ascending: true , startingValues: Array ( 0 ..< 10000 ) )
56
+ measure {
57
+ var pq = original
56
58
for x in 0 ..< 100 {
57
- pq. remove ( x * x)
58
- }
59
- }
60
- }
61
-
59
+ pq. remove ( x * x)
60
+ }
61
+ }
62
+ }
63
+
62
64
static var allTests = [
63
- ( " testBuildPerformance " , testBuildPerformance) ,
64
- ( " testPopPerformance " , testPopPerformance) ,
65
- ( " testPushPerformance " , testPushPerformance) ,
66
- ( " testRemovePerformance " , testRemovePerformance)
65
+ ( " testBuildPerformance " , testBuildPerformance) ,
66
+ ( " testPopPerformance " , testPopPerformance) ,
67
+ ( " testPushPerformance " , testPushPerformance) ,
68
+ ( " testRemovePerformance " , testRemovePerformance)
67
69
]
68
70
}
0 commit comments