Benchmark of Swift extensions vs methods: Swift 4.1 (May 2018)

Interactive charts are available here: http://minikin.me/extensions

🤼‍ Motivation

👨🏻‍🔬 Benchmarking

class MyClass {
let n = 1000
func method_1() {
for item in 0..<n { let newItem = item + 2; print(newItem)}
}
func method_2() {
for item in 0..<n { let newItem = item + 2; print(newItem)}
}
func method_3() {
for item in 0..<n { let newItem = item + 2; print(newItem)}
}
}
class MyClass {
let n = 1000
func method_1() {
for item in 0..<n { let newItem = item + 2; print(newItem)}
}
}

extension MyClass {
func method_ext_1() {
for item in 0..<n { let newItem = item + 2; print(newItem)}
}
}
extension MyClass {
func method_ext_2() {
for item in 0..<n { let newItem = item + 2; print(newItem)}
}
}
extension MyClass {
func method_ext_3() {
for item in 0..<n { let newItem = item + 2; print(newItem)}
}
}
* — our apps have about these numbers of extensions
rake benchmark
rake clean

📈 Results

Interactive charts are available here: http://minikin.me/extensions
Results

🧐 Conclusions

Software Engineer with a decade of experience in software engineering — https://minikin.me

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store