Skip to content

Instantly share code, notes, and snippets.

@yusuke024
Created June 29, 2018 08:09
Show Gist options
  • Save yusuke024/41a4695789d32156c069369ccfb566c3 to your computer and use it in GitHub Desktop.
Save yusuke024/41a4695789d32156c069369ccfb566c3 to your computer and use it in GitHub Desktop.
import XCTest
final class Static {
func a() { 1 + 1 }
func b() { a() }
func c() { b() }
}
class Dynamic {
func a() { 1 + 1 }
func b() { a() }
func c() { b() }
}
class Dynamic1: Dynamic { }
class Dynamic2: Dynamic1 { }
class Dynamic3: Dynamic2 {
override func a() { 1 + 1 }
override func b() { a() }
override func c() { b() }
}
class MyTestCase: XCTestCase {
func testStatic() {
let s = Static()
measure {
for _ in 0..<10000 {
s.c()
}
}
}
func testDynamic() {
let d: Dynamic
d = Dynamic3()
measure {
for _ in 0..<10000 {
d.c()
}
}
}
}
MyTestCase.defaultTestSuite.run() // Swift 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment