Last active
December 14, 2015 07:34
-
-
Save dduan/279b3a1a83e31cec5ec1 to your computer and use it in GitHub Desktop.
A simple program to benchmark performance of removeAll() method for Set
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 Foundation | |
var before = NSDate() | |
var after = NSDate() | |
var duration: NSTimeInterval = 0 | |
var a = Set(Array(1..<9999).sort {_, _ in arc4random() % 2 == 0}) | |
(1...10000).forEach { _ in | |
var b = a | |
before = NSDate() | |
b.removeAll(keepCapacity: true) | |
after = NSDate() | |
duration += after.timeIntervalSinceDate(before) | |
} | |
print(duration) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment