Created
June 25, 2018 13:48
-
-
Save zintus/5c640b2b3edd67ebb1fd413a85713304 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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