-
Notifications
You must be signed in to change notification settings - Fork 265
Expand file tree
/
Copy pathSingleSectionPerformanceTest.swift
More file actions
58 lines (50 loc) · 1.53 KB
/
SingleSectionPerformanceTest.swift
File metadata and controls
58 lines (50 loc) · 1.53 KB
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
//
// PerformanceTest.swift
// CollectionKitTests
//
// Created by Luke Zhao on 2018-12-03.
// Copyright © 2018 lkzhao. All rights reserved.
//
@testable import CollectionKit
import XCTest
class SingleSectionPerformanceTest: XCTestCase {
var collectionView: CollectionView!
override func setUp() {
collectionView = CollectionView(frame: CGRect(x: 0, y: 0, width: 100, height: 1000))
collectionView.showsVerticalScrollIndicator = false
collectionView.showsHorizontalScrollIndicator = false
let dataSource = ArrayDataSource(data: Array(0..<100000))
let provider = BasicProvider(
dataSource: dataSource,
viewSource: { (label: UILabel, data: Int, index: Int) in },
sizeSource: { (index: Int, data: Int, collectionSize: CGSize) -> CGSize in
return CGSize(width: 50, height: 50)
})
collectionView.provider = provider
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
func testReloadPerformance() {
measure {
collectionView.reloadData()
}
}
func testVisibleIndexesPerformance() {
measure {
for _ in 0..<1000 {
collectionView.bounds.origin.y += 100
_ = collectionView.provider!.visibleIndexes(visibleFrame: collectionView.bounds)
}
}
}
func testScrollPerformance() {
collectionView.reloadData()
measure {
for _ in 0..<1000 {
collectionView.bounds.origin.y += 10
collectionView.layoutSubviews()
}
}
}
}