Skip to content

Instantly share code, notes, and snippets.

@zintus
Created June 25, 2018 13:48
Show Gist options
  • Save zintus/5c640b2b3edd67ebb1fd413a85713304 to your computer and use it in GitHub Desktop.
Save zintus/5c640b2b3edd67ebb1fd413a85713304 to your computer and use it in GitHub Desktop.
import XCTest
class PerformanceTest: XCTestCase {
func testString() { // 0.265s on iPhone X
var array = [String]()
let strings = Array(1 ... 1_000_000).map { String($0) }
measure {
strings.forEach {
array.append($0)
}
}
print(array.count)
}
func testNSString() { // 0.508 s on iPhone X
var array = [NSString]()
let strings = Array(1 ... 1_000_000).map { String($0) }
measure {
strings.forEach {
array.append($0 as NSString)
}
}
print(array.count)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment