-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppDelegate.m
107 lines (82 loc) · 3.66 KB
/
AppDelegate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// AppDelegate.m
// iPhoneExpat
//
// Created by Ben Reeves on 22/05/2010.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "AppDelegate.h"
@implementation AppDelegate
-(void)applicationDidFinishLaunching:(UIApplication *)application {
NSArray * urls = [NSArray arrayWithObjects:@"http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topalbums/sf=143441/limit=300/explicit=true/xml",
@"http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topalbums/sf=143441/limit=300/explicit=true/xml",
@"http://feeds.feedburner.com/DilbertDailyStrip",
@"http://designsponge.blogspot.com/atom.xml",
@"http://www.slate.com/rss/",
@"http://rssfeeds.usatoday.com/UsatodaycomBooks-TopStories",
@"http://googleblog.blogspot.com/atom.xml",
@"http://api.flickr.com/services/feeds/groups_pool.gne?id=61057342@N00&lang=en-us&format=rss_200",
@"http://phobos.apple.com/WebObjects/MZStore.woa/wpa/MRSS/topsongs/limit=25/rss.xml",
@"http://www.readwriteweb.com/rss.xml",
@"http://rssfeeds.usatoday.com/UsatodaycomNation-TopStories",
@"http://dictionary.reference.com/wordoftheday/wotd.rss",
@"http://www.quotationspage.com/data/qotd.rss",
@"http://sports.espn.go.com/espn/rss/news", nil];
for (NSString * urlString in urls) {
timePrinted = NO;
opened = 0;
closed = 0;
NSLog(@"Begin Parsing Using Expat");
start = [[NSDate date] timeIntervalSince1970];
ExpatXMLParser * parser = [[ExpatXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:urlString]];
parser.delegate = self;
//[parser setShouldProcessNamespaces:YES];
[parser parse];
[parser release];
end = [[NSDate date] timeIntervalSince1970];
totalExpat += end-start;
totalExpatReachFirst += firstElementTime-start;
printf("Time Taken to Reach first element %f\n", firstElementTime-start);
printf("Total time %f\n", end-start);
NSLog(@"opened %d -- closed %d", opened, closed);
urlString = [urlString stringByAppendingFormat:@"?=%d", arc4random()];
NSLog(@"%@", urlString);
timePrinted = NO;
opened = 0;
closed = 0;
NSLog(@"Begin Parsing Using NSXMLParser");
start = [[NSDate date] timeIntervalSince1970];
NSXMLParser * parserns = [[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:urlString]];
parserns.delegate = self;
[parserns setShouldProcessNamespaces:YES];
[parserns parse];
[parserns release];
end = [[NSDate date] timeIntervalSince1970];
totalNSXML += end-start;
totalNSXMLReachFirst += firstElementTime-start;
printf("Time Taken to Reach first element %f\n", firstElementTime-start);
printf("Total time %f\n", end-start);
urlString = [urlString stringByAppendingFormat:@"?=%d", arc4random()];
NSLog(@"opened %d -- closed %d", opened, closed);
}
NSLog(@"time to reach the first element Expat: %f -- NSXMLParser: %f\n", totalExpatReachFirst, totalNSXMLReachFirst);
NSLog(@"Total time for Expat: %f -- NSXMLParser: %f\n", totalExpat, totalNSXML);
}
- (void)parser:(ExpatXMLParser *)parser foundCharacters:(NSString *)string {
}
- (void)parser:(ExpatXMLParser*)parser parseErrorOccurred:(NSError *)parseError {
NSLog(@"%@", parseError);
}
- (void)parser:(ExpatXMLParser*)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
{
if (timePrinted == NO) {
firstElementTime = [[NSDate date] timeIntervalSince1970];
timePrinted = YES;
}
++opened;
}
- (void)parser:(ExpatXMLParser*)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
++closed;
}
@end