Created
March 1, 2010 23:57
-
-
Save takuma104/318957 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
#import "YAJL.h" // YAJL ObjC | |
#import "NSString+SBJSON.h" // JSON Framework | |
// JSON Data: Twitter Home Timeline (count=200) | |
// iPod touch 3rd Gen -> test0:296ms test1:323ms test2:170ms test3:488ms | |
@implementation Test | |
- (void)test0:(NSData*)JSONData { | |
double st = CFAbsoluteTimeGetCurrent(); | |
[JSONData yajl_JSON]; | |
NSLog(@"test0: %.0fms", (CFAbsoluteTimeGetCurrent() - st)*1000.0); | |
} | |
- (void)test1:(NSData*)JSONData { | |
double st = CFAbsoluteTimeGetCurrent(); | |
NSError *error = nil; | |
YAJLDocument *document = [[YAJLDocument alloc] initWithData:JSONData | |
parserOptions:0 error:&error]; | |
document.root; | |
[document release]; | |
NSLog(@"test1: %.0fms", (CFAbsoluteTimeGetCurrent() - st)*1000.0); | |
} | |
- (void)test2:(NSData*)JSONData { | |
double st = CFAbsoluteTimeGetCurrent(); | |
YAJLParser *parser = [[YAJLParser alloc] initWithParserOptions:0]; | |
parser.delegate = self; | |
[parser parse:JSONData]; | |
if (parser.parserError) { | |
NSLog(@"Error:\n%@", parser.parserError); | |
} | |
parser.delegate = nil; | |
[parser release]; | |
NSLog(@"test2: %.0fms", (CFAbsoluteTimeGetCurrent() - st)*1000.0); | |
} | |
- (void)test3:(NSData*)JSONData { | |
NSString *json = [[[NSString alloc] initWithData:JSONData | |
encoding:NSUTF8StringEncoding] autorelease]; | |
double st = CFAbsoluteTimeGetCurrent(); | |
[json JSONValue]; | |
NSLog(@"test3: %.0fms", (CFAbsoluteTimeGetCurrent() - st)*1000.0); | |
} | |
- (void)allTest { | |
NSString *path = [[NSBundle mainBundle] pathForResource:@"timeline200" | |
ofType:@"json"]; | |
NSData *JSONData = [NSData dataWithContentsOfFile:path]; | |
NSAutoreleasePool *pool; | |
pool = [[NSAutoreleasePool alloc] init]; | |
[self test0:JSONData]; | |
[pool release]; | |
pool = [[NSAutoreleasePool alloc] init]; | |
[self test1:JSONData]; | |
[pool release]; | |
pool = [[NSAutoreleasePool alloc] init]; | |
[self test2:JSONData]; | |
[pool release]; | |
pool = [[NSAutoreleasePool alloc] init]; | |
[self test3:JSONData]; | |
[pool release]; | |
[self performSelector:@selector(allTest) | |
withObject:nil | |
afterDelay:3.0]; | |
} | |
#pragma mark YAJLParserDelegate | |
- (void)parserDidStartDictionary:(YAJLParser *)parser { | |
} | |
- (void)parserDidEndDictionary:(YAJLParser *)parser { | |
} | |
- (void)parserDidStartArray:(YAJLParser *)parser { | |
} | |
- (void)parserDidEndArray:(YAJLParser *)parser { | |
} | |
- (void)parser:(YAJLParser *)parser didMapKey:(NSString *)key { | |
} | |
- (void)parser:(YAJLParser *)parser didAdd:(id)value { | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment