Skip to content

add a few performance test #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CollectionKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
A363C56A20C955C7009A885F /* LayoutContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = A363C56920C955C7009A885F /* LayoutContext.swift */; };
A363C56C20CACA8A009A885F /* FlattenedProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = A363C56B20CACA89009A885F /* FlattenedProvider.swift */; };
A363C56E20CBD55B009A885F /* ComposedHeaderProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = A363C56D20CBD55B009A885F /* ComposedHeaderProvider.swift */; };
A376B2E921B5A00E00A027BD /* SingleSectionPerformanceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = A376B2E821B5A00E00A027BD /* SingleSectionPerformanceTest.swift */; };
A376B2EB21B5A43900A027BD /* ComposedSectionPerformanceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = A376B2EA21B5A43900A027BD /* ComposedSectionPerformanceTest.swift */; };
A39C84932177B028002084AD /* WaterfallLayoutSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = A39C84922177B028002084AD /* WaterfallLayoutSpec.swift */; };
A39C84952177B347002084AD /* BasicProviderSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = A39C84942177B347002084AD /* BasicProviderSpec.swift */; };
A39C849D2177BF9B002084AD /* SimpleViewSizeSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = A39C849B2177BF8B002084AD /* SimpleViewSizeSource.swift */; };
Expand Down Expand Up @@ -97,6 +99,8 @@
A363C56920C955C7009A885F /* LayoutContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutContext.swift; sourceTree = "<group>"; };
A363C56B20CACA89009A885F /* FlattenedProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlattenedProvider.swift; sourceTree = "<group>"; };
A363C56D20CBD55B009A885F /* ComposedHeaderProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComposedHeaderProvider.swift; sourceTree = "<group>"; };
A376B2E821B5A00E00A027BD /* SingleSectionPerformanceTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleSectionPerformanceTest.swift; sourceTree = "<group>"; };
A376B2EA21B5A43900A027BD /* ComposedSectionPerformanceTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComposedSectionPerformanceTest.swift; sourceTree = "<group>"; };
A39C84922177B028002084AD /* WaterfallLayoutSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WaterfallLayoutSpec.swift; sourceTree = "<group>"; };
A39C84942177B347002084AD /* BasicProviderSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicProviderSpec.swift; sourceTree = "<group>"; };
A39C84972177BF49002084AD /* UIImageSizeSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIImageSizeSource.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -363,6 +367,8 @@
B145FF9F1F5BB4D700A4F318 /* ComposedProviderSpec.swift */,
A39C84A12177E223002084AD /* ComposedHeaderProviderSpec.swift */,
A3328EB5218B96A000A28AE8 /* EmptyStateProviderSpec.swift */,
A376B2E821B5A00E00A027BD /* SingleSectionPerformanceTest.swift */,
A376B2EA21B5A43900A027BD /* ComposedSectionPerformanceTest.swift */,
);
path = CollectionKitTests;
sourceTree = SOURCE_ROOT;
Expand Down Expand Up @@ -542,7 +548,9 @@
B19D64D01F23DE8100D02FDB /* RowLayoutSpec.swift in Sources */,
B145FFA01F5BB4D700A4F318 /* ComposedProviderSpec.swift in Sources */,
0E3258451F5E23B000D455F8 /* FlowLayoutSpec.swift in Sources */,
A376B2EB21B5A43900A027BD /* ComposedSectionPerformanceTest.swift in Sources */,
A39C84932177B028002084AD /* WaterfallLayoutSpec.swift in Sources */,
A376B2E921B5A00E00A027BD /* SingleSectionPerformanceTest.swift in Sources */,
A39C84952177B347002084AD /* BasicProviderSpec.swift in Sources */,
B1A8E2DD1F59E99500172387 /* CollectionViewSpec.swift in Sources */,
A3328EB6218B96A000A28AE8 /* EmptyStateProviderSpec.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>classNames</key>
<dict>
<key>ComposedSectionPerformanceTest</key>
<dict>
<key>testReloadPerformance()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.26296</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
<key>testScrollPerformance()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.42</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
<key>testVisibleIndexesPerformance()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.0033543</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
</dict>
<key>SingleSectionPerformanceTest</key>
<dict>
<key>testReloadPerformance()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.19627</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
<key>testScrollPerformance()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.14618</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
<key>testVisibleIndexesPerformance()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.0016359</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
</dict>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>runDestinationsByUUID</key>
<dict>
<key>5BE1D297-F4EF-4D65-9F0C-B607EC8797C3</key>
<dict>
<key>localComputer</key>
<dict>
<key>busSpeedInMHz</key>
<integer>400</integer>
<key>cpuCount</key>
<integer>1</integer>
<key>cpuKind</key>
<string>Intel Core i9</string>
<key>cpuSpeedInMHz</key>
<integer>2900</integer>
<key>logicalCPUCoresPerPackage</key>
<integer>12</integer>
<key>modelCode</key>
<string>MacBookPro15,1</string>
<key>physicalCPUCoresPerPackage</key>
<integer>6</integer>
<key>platformIdentifier</key>
<string>com.apple.platform.macosx</string>
</dict>
<key>targetArchitecture</key>
<string>x86_64</string>
<key>targetDevice</key>
<dict>
<key>modelCode</key>
<string>iPhone10,4</string>
<key>platformIdentifier</key>
<string>com.apple.platform.iphonesimulator</string>
</dict>
</dict>
</dict>
</dict>
</plist>
62 changes: 62 additions & 0 deletions CollectionKitTests/ComposedSectionPerformanceTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// ComposedSectionPerformanceTest.swift
// CollectionKitTests
//
// Created by Luke Zhao on 2018-12-03.
// Copyright © 2018 lkzhao. All rights reserved.
//

@testable import CollectionKit
import XCTest

class ComposedSectionPerformanceTest: 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 sections: [ComposedProvider] = (0..<10).map { _ in
let sections: [Provider] = (0..<100).map { _ in
let viewSource = ClosureViewSource<Int, UIView>(viewUpdater: { _, _, _ in })
viewSource.reuseManager.removeFromCollectionViewWhenReuse = true
return BasicProvider(dataSource: Array(0..<100), viewSource: viewSource,
sizeSource: { _, _, _ in return CGSize(width: 100, height: 100) })
}
return ComposedProvider(sections: sections)
}
let provider = ComposedProvider(layout: RowLayout().transposed(), sections: sections)
collectionView.provider = provider
collectionView.reloadData()
}

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() {
measure {
for _ in 0..<1000 {
collectionView.bounds.origin.y += 100
collectionView.layoutSubviews()
}
}
}

}
58 changes: 58 additions & 0 deletions CollectionKitTests/SingleSectionPerformanceTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,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()
}
}
}

}