Last active
August 22, 2017 09:28
-
-
Save paulw11/68221cc3bf7ae98f62c6e8c773621f9e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// | |
// main.swift | |
// SearchTest | |
// | |
// Created by Paul Wilkinson on 22/8/17. | |
// Copyright © 2017 Paul Wilkinson. All rights reserved. | |
// | |
import Foundation | |
class Thing: NSObject { | |
var uuid: String | |
init(uuid: String) { | |
self.uuid = uuid | |
} | |
} | |
var things = [Thing]() | |
for i in 0...10000 { | |
let newThing = Thing(uuid: UUID().uuidString) | |
things.append(newThing) | |
} | |
var start=Date() | |
let random = Int(arc4random_uniform(UInt32(things.count))) | |
let searchThing = things[random] | |
let predicate = NSPredicate(format: "uuid == %@", searchThing.uuid) | |
let thing = (things as NSArray).filtered(using: predicate) | |
print(Date().timeIntervalSince(start)) | |
start = Date() | |
var outputArray = [Thing]() | |
for compareThing in things { | |
if compareThing.uuid == searchThing.uuid { | |
outputArray.append(compareThing) | |
} | |
} | |
print(Date().timeIntervalSince(start)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment