I'm trying to understand NSURLConnection performance on a 3G network from an iPhone. I have the following test code
-(void)doTest2 {
max = 5;
NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
NSURLRequest *request2 = [[[NSURLRequest alloc] initWithURL:url] autorelease];
NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:request2 delegate:self];
self.startDate = [NSDate date];
if (conn)
{
receivedData = [[NSMutableData data] retain];
} }
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
self.endDate = [NSDate date];
NSTimeInterval interval = [self.endDate timeIntervalSinceDate:self.startDate];
NSLog(@"Time:%f Size:%u", interval, [receivedData length]);
[receivedData release];
count = count + 1;
if (count == max) {
count = 0;
sleep(3);
}
self.doTest2;}
The very first request is slow (over 1 second). Requests 2-5 are fast (under .25 seconds). If I sleep for 3 or more seconds, the first request after the sleep is slow. But if I sleep for less than 3 seconds, it's fast. Any ideas why?