Last active
December 29, 2015 19:15
-
-
Save theladyjaye/9615730413415d4470d9 to your computer and use it in GitHub Desktop.
Realm Primary Key Insert Performance @ 1 million + 1 records
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 | |
import RealmSwift | |
class StringObject: Object{ | |
dynamic var id: String = "" | |
override static func primaryKey() -> String{ | |
return "id" | |
} | |
} | |
class IntObject: Object{ | |
dynamic var id: Int = 0 | |
override static func primaryKey() -> String{ | |
return "id" | |
} | |
} |
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
func testIntPerformanceExample() { | |
let realm = db.realm | |
let ids = (0..<max).map{ i -> IntObject in | |
let obj = IntObject() | |
obj.id = i | |
return obj | |
} | |
try! realm.write { | |
ids.forEach{ obj in | |
realm.add(obj) | |
} | |
} | |
let obj = IntObject() | |
obj.id = max + 1 | |
self.measureBlock { | |
try! realm.write { | |
realm.add(obj) | |
} | |
} | |
} |
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
func testUUIDPerformanceInsertPerformance() { | |
let realm = db.realm | |
let ids = (0..<max).map{ _ -> StringObject in | |
let obj = StringObject() | |
obj.id = NSUUID().UUIDString | |
return obj | |
} | |
try! realm.write { | |
ids.forEach{ obj in | |
realm.add(obj) | |
} | |
} | |
let obj = StringObject() | |
obj.id = NSUUID().UUIDString | |
self.measureBlock { | |
try! realm.write { | |
realm.add(obj) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment