Skip to content

Instantly share code, notes, and snippets.

@dduan
Last active December 14, 2015 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dduan/279b3a1a83e31cec5ec1 to your computer and use it in GitHub Desktop.
Save dduan/279b3a1a83e31cec5ec1 to your computer and use it in GitHub Desktop.
A simple program to benchmark performance of removeAll() method for Set
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