Hi,
We've been benchmarking NSURLSession against NSURLConnection/dataWithContentsOfURL. The former is consistently slower on the watch/watch SIM:
NSString *urlString = [NSString stringWithFormat:@"HERE_GOES_THE_SERVER?%d",arc4random_uniform(1000000000)];
NSLog(@"Started");
NSData* data = [NSData dataWithContentsOfURL:[NSURL URLWithString: urlString] options:NSDataReadingUncached error:nil];
NSLog(@"Finished");
urlString = [NSString stringWithFormat:@"HERE_GOES_THE_SERVER?%d",arc4random_uniform(1000000000)];
NSURL * url = [NSURL URLWithString: urlString];
NSLog(@"Started");
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:1];
NSURLSessionDataTask *dataTask = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error)
{
NSLog(@"Finished");
}];
[dataTask resume];
The random number in the URL is to avoid caches, I'm testing against both my own server and some public servers (Google, others).
2015-09-10 16:46:49.321 SpeedTest WatchKit Extension[1153:16410] Started
2015-09-10 16:46:49.474 SpeedTest WatchKit Extension[1153:16410] Finished
2015-09-10 16:46:49.483 SpeedTest WatchKit Extension[1153:16410] Started
2015-09-10 16:46:52.122 SpeedTest WatchKit Extension[1153:16764] Finished
As you can see the first method (dataWithContentsOfURL) is much faster than the second. NSURLConnection was also much faster, so we started using it, but in the GM it has been removed from the watch. So we are back to square one, using NSURLSession, even if it is 20 times slower (much more if we use HTTPS servers).
We've tried all that comes to our mind when trying to configure NSURLSession to no avail, it's always much slower. And now we don't have the alternative (to use a NSURLConnection).
This doesn't happen in iOS9. Any idea of why this is happening? Is it a bug on watchOS?