Skip to content

Instantly share code, notes, and snippets.

@Joannis
Created October 27, 2018 21:08
Show Gist options
  • Save Joannis/bc63701ea334430b03031414e93c634f to your computer and use it in GitHub Desktop.
Save Joannis/bc63701ea334430b03031414e93c634f to your computer and use it in GitHub Desktop.
Code using the Any type
import Foundation
let date = Date()
var array = [Any]()
for _ in 0..<100_000 {
array.append("Hello, world")
}
var array2 = [Any]()
for _ in 0..<100_000 {
array2.append(array.removeLast())
}
print(Date().timeIntervalSince(date))
print(array2.count)
@Joannis
Copy link
Author

Joannis commented Oct 27, 2018

59ms on debug, 11ms on release both rounded to nearest the ms (rounded down)

If you replace Any with String it becomes:
28ms on debug and 4 ms both rounded to nearest the ms (up)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment