Skip to content

Commit 9ef52ec

Browse files
author
Luc Dion
committed
Add documentation about PinLayout’s performance.
The performance are really incredible, I didn’t know they would be that great. As you can see in the following chart, PinLayout's performance is as fast as manual layouting, and up to **12x faster than auto layout**, and **16x faster than UIStackViews**. LayoutKit is also realy fast, slightly slower than PinLayout and manual layouting. These results also means that PinLayout is by far faster than any layout frameworks that is built over auto layout ([SnapKit](https://github.com/SnapKit/SnapKit), [Stevia](https://github.com/freshOS/Stevia), [PureLayout](https://github.com/PureLayout/PureLayout), ...). It takes almost half a second (0.468 ms) to render 100 UICollectionView's cells using UIStackViews, and 1/3 of second (0.344) using auto layout. And all these results are on a iPhone 6S device.
1 parent 75e5a26 commit 9ef52ec

8 files changed

+101
-31
lines changed

Docs/Benchmark.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<p align="center">
2+
<img src="pinlayout-logo-small.png" alt="PinLayout Performance" width=100/>
3+
</p>
4+
5+
<h1 align="center" style="color: #376C9D; font-family: Arial Black, Gadget, sans-serif; font-size: 1.5em">PinLayout Benchmark</h1>
6+
7+
## Methodology
8+
9+
##### LayoutKit Benchmark
10+
PinLayout's performance has been tested using a fork of [LayoutKit](https://github.com/mirego/LayoutKit). LayoutKit's example app include a really nice benchmark.
11+
12+
The benchmark has been modified to also include PinLayout. [See PinLayout implementation source code](https://github.com/mirego/LayoutKit/blob/master/LayoutKitSampleApp/Benchmarks/FeedItemPinLayoutView.swift). Remark that PinLayout's layout code is concise, clean and doesn't contain any computation in `layoutSubviews()`, compared to [Manual Layouting source code](https://github.com/mirego/LayoutKit/blob/master/LayoutKitSampleApp/Benchmarks/FeedItemManualView.swift)
13+
14+
The benchmark include tests for the following layout systems:
15+
16+
* Auto layout
17+
* Auto layout using UIStackViews
18+
* LayoutKit
19+
* Manual layout (i.e. set UIView's frame directly)
20+
* PinLayout
21+
22+
Anyone who would like to integrate any other layout frameworks to this GitHub repository is welcome.
23+
24+
##### Benchmark details
25+
The LayoutKit benchmark layout UICollectionView and UITableView cells in multiple pass, each pass contains more cells than the previous one. The **X axis** in following charts indicates the number of cell contained for each pass. The **Y axis** indicates the number of miliseconds to render all cells from one pass.
26+
27+
Here are the rendering results to compare visual results:
28+
29+
* [Auto layout rendering result](Benchmark/Benchmark-Autolayout.png)
30+
* [LayoutKit rendering result](Benchmark/Benchmark-PinLayout.png)
31+
* [PinLayout rendering result](Benchmark/Benchmark-LayoutKit.png)
32+
33+
## Results
34+
35+
As you can see in the following chart, PinLayout's performance is as fast as manual layouting, and up to **12x faster than auto layout**, and **16x faster than UIStackViews**. LayoutKit is also realy fast, slightly slower than PinLayout and manual layouting.
36+
37+
These results also means that PinLayout is by far faster than any layout frameworks that is built over auto layout ([SnapKit](https://github.com/SnapKit/SnapKit), [Stevia](https://github.com/freshOS/Stevia), [PureLayout](https://github.com/PureLayout/PureLayout), ...).
38+
39+
It takes almost half a second (0.468 ms) to render 100 UICollectionView's cells using UIStackViews, and 1/3 of second (0.344) using auto layout. And all these results are on a iPhone 6S device.
40+
41+
42+
<p align="center">iPhone 6S - iOS 10.3.2</p>
43+
<p align="center">
44+
<a href="https://mirego.github.io/PinLayout/"><img src="Benchmark/Chart-iPhone6S.png" alt="PinLayout Performance"/></a>
45+
<p align="center" style="font-size:10px;">X axis in the number cells in a UICollectionView, and Y axis is the time in miliseconds to layout all cells.</p>
46+
</p>
47+
48+
You can have a look at the [spreadsheet containing all the data](Benchmark/Benchmark-iPhone6S.xlsx)
49+
50+
### Other device's chart will be coming soon...
106 KB
Loading
124 KB
Loading
94.7 KB
Loading
16.4 KB
Binary file not shown.

Docs/Benchmark/Chart-iPhone6S.png

145 KB
Loading
31.2 KB
Binary file not shown.

README.md

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
<br>
1818

19-
Swift manual views layouting without auto layout, no magic, pure code, full control. Concise syntax, readable & chainable.
19+
Swift manual views layouting without auto layout, no magic, pure code, full control and FAST! Concise syntax, readable & chainable.
2020

2121
> "No auto-layout constraints attached"
2222
2323
<br>
2424

2525
* [PinLayout principles and philosophy](#introduction)
26-
* [Installation](#installation)
26+
* [Performance](#performance)
2727
* [Documentation](#documentation)
2828
* [Layout using distances from superview’s edges](#distance_from_superview_edge)
2929
* [Anchors](#anchors)
@@ -34,6 +34,7 @@ Swift manual views layouting without auto layout, no magic, pure code, full cont
3434
* [Warnings](#warnings)
3535
* [More examples](#more_examples)
3636

37+
* [Installation](#installation)
3738
* [FAQ](#faq)
3839
* [Comments, ideas, suggestions, issues, ....](#comments)
3940

@@ -42,6 +43,7 @@ Swift manual views layouting without auto layout, no magic, pure code, full cont
4243
## PinLayout principles and philosophy <a name="introduction"></a>
4344

4445
* Manual layouting. No magic, pure code, full control.
46+
* Fast, PinLayout exist to be simple and fast as possible! In fact it is fast as manual layouting. See [performance results below.](#performance)
4547
* Layout one view at a time.
4648
* Concise syntax. Layout most views using a single line.
4749

@@ -71,39 +73,24 @@ A view can be layouted using PinLayout and later with another method/framework.
7173

7274
<br>
7375

74-
## Installation <a name="installation"></a>
76+
# PinLayout's Performance <a name="performance"></a>
7577

76-
### CocoaPods
78+
PinLayout's performance has been measured using the excellent LayoutKit benchmark, which has been developped to compared LayoutKit performance over UIStackView, Auto layout and manual layouting. [PinLayout has been added to this benchmark](https://github.com/mirego/LayoutKit)
79+
to compare its performance.
7780

78-
To integrate PinLayout into your Xcode project using CocoaPods, specify it in your `Podfile`:
81+
As you can see in the following chart, PinLayout's performance is as fast as manual layouting, and up to **12x faster than auto layout**, and **16x faster than UIStackViews**.
7982

80-
```ruby
81-
pod 'PinLayout'
82-
```
83+
These results also means that **PinLayout is by far faster than any layout frameworks that is built over auto layout**.
8384

84-
Then, run `pod install`.
85-
86-
### Carthage
87-
88-
To integrate PinLayout into your Xcode project using Carthage, specify it in your `Cartfile`:
89-
90-
```ogdl
91-
github "mirego/PinLayout"
92-
```
85+
[More details and explanation of the benchmark](Docs/Benchmark)
9386

94-
Then, run `carthage update` to build the framework and drag the built `PinLayout.framework` into your Xcode project.
95-
96-
### Swift Package Manager
97-
98-
Once you have your Swift package set up, you only need to add PinLayout as a dependency of your `Package.swift`.
99-
100-
```ogdl
101-
dependencies: [
102-
.Package(url: "https://github.com/mirego/PinLayout.git", majorVersion: 1)
103-
]
104-
```
87+
<p align="center"> Tested on a iPhone 6S iOS 10.3.2</p>
88+
<p align="center">
89+
<a href="https://mirego.github.io/PinLayout/"><img src="Docs/Benchmark/Chart-iPhone6S.png" alt="PinLayout Performance" width=500/></a>
90+
<p align="center" style="font-size:10px;">X axis in the number cells in a UICollectionView, and Y axis is the time in miliseconds to layout all cells.</p>
91+
</p>
10592

106-
<br>
93+
<br/>
10794

10895
# Usage sample
10996
###### Example:
@@ -133,13 +120,12 @@ override func layoutSubviews() {
133120
}
134121
```
135122

136-
:pushpin: This example and some other examples are available in the **PinLayoutSample** project. Please note that you must do a `pod install` before running the sample project.
123+
:pushpin: This example and some other examples are available in the **Example** project. Please note that you must do a `pod install` before running the example project.
137124

138125
:pushpin: PinLayout doesn't use auto layout constraints, it is a framework that manually layout views. For that reason you need to update the layout inside either `UIView.layoutSubviews()` or `UIViewController.viewDidLayoutSubviews()` to handle container size's changes, including device rotation. You'll also need to handle UITraitCollection changes for app's that support multitask. In the example above PinLayout's commands are inside UIView's `layoutSubviews()` method.
139126

140127
<br/>
141128

142-
143129
# Documentation <a name="documentation"></a>
144130

145131
## Layout using distances from superview’s edges <a name="distance_from_superview_edge"></a>
@@ -788,6 +774,40 @@ Cell D:
788774

789775
<br>
790776

777+
## Installation <a name="installation"></a>
778+
779+
### CocoaPods
780+
781+
To integrate PinLayout into your Xcode project using CocoaPods, specify it in your `Podfile`:
782+
783+
```ruby
784+
pod 'PinLayout'
785+
```
786+
787+
Then, run `pod install`.
788+
789+
### Carthage
790+
791+
To integrate PinLayout into your Xcode project using Carthage, specify it in your `Cartfile`:
792+
793+
```ogdl
794+
github "mirego/PinLayout"
795+
```
796+
797+
Then, run `carthage update` to build the framework and drag the built `PinLayout.framework` into your Xcode project.
798+
799+
### Swift Package Manager
800+
801+
Once you have your Swift package set up, you only need to add PinLayout as a dependency of your `Package.swift`.
802+
803+
```ogdl
804+
dependencies: [
805+
.Package(url: "https://github.com/mirego/PinLayout.git", majorVersion: 1)
806+
]
807+
```
808+
809+
<br>
810+
791811
## Coming soon <a name="coming_soon"></a>
792812
* minWidth/maxWidth, minHeight/maxHeight
793813
* CALayer support

0 commit comments

Comments
 (0)