Performance testing

This commit is contained in:
Kevin Renskers
2013-01-28 17:00:35 +00:00
parent 9aaa668109
commit c67485666a
2 changed files with 35 additions and 4 deletions

View File

@@ -115,6 +115,36 @@
NSLog(@"floatValue: %f", [[NSUserDefaults standardUserDefaults] floatForKey:@"NSUserDefaultFloatValue"]);
NSLog(@"floatValue OBJECT: %@", [[NSUserDefaults standardUserDefaults] objectForKey:@"NSUserDefaultFloatValue"]);
NSLog(@"--------------------");
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
LogTimestamp;
NSString *value;
for (int i=0; i<4; i++) {
value = [[NSUserDefaults standardUserDefaults] objectForKey:@"NSUserDefaultUserName"];
}
LogTimestamp;
for (int i=0; i<4; i++) {
value = [GVUserDefaults standardUserDefaults].userName;
}
LogTimestamp;
for (int i=0; i<4; i++) {
[[NSUserDefaults standardUserDefaults] setObject:@"Test 3" forKey:@"NSUserDefaultUserName"];
}
LogTimestamp;
for (int i=0; i<4; i++) {
[GVUserDefaults standardUserDefaults].userName = @"Test 3";
}
LogTimestamp;
}
@end

View File

@@ -43,7 +43,8 @@ Registering defaults can be done as usual, on NSUserDefaults directly (use the s
NSDictionary *defaults = @{
@"NSUserDefaultUserName": @"default",
@"NSUserDefaultUserId": @1
@"NSUserDefaultUserId": @1,
@"NSUserDefaultBoolValue": @YES
};
[[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
@@ -53,14 +54,14 @@ However, it's a lot easier to create a setupDefaults method on the category, whi
- (NSDictionary *)setupDefaults {
return @{
@"userName": @"default",
@"userId": @1
@"userId": @1,
@"boolValue": @YES
};
}
### Performance
The getter is about 3 times as slow as directly using NSUserDefaults, but we're talking about fractions of a millisecond (0.22 ms vs 0.65 ms on an iPod Touch 4th gen). The setter is about 3 times as slow as well (0.20 ms vs 0.61 ms).
The numbers vary a bit from device to device and from run to run, but it always seems to be about 1.5 to 3 times as slow. For example on an iPhone 4 the setter takes 0.77 ms vs 0.5 ms when you do it natively.
Performance is nearly identical to using NSUserDefaults directly. We're talking about a difference of 0.05 milliseconds or less.
## Install