0

JSONWebサービスからデータがダウンロードされるまでにかかる時間をテストするにはどうすればよいですか。

現在、私は次のコードを使用しており、ダウンロードにかかる時間をNSLogに記録したいと思います。

- (void)downloadData{

// Download the JSON
NSString *jsonString = [NSString
                        stringWithContentsOfURL:[NSURL URLWithString:queryLine]
                        encoding:NSStringEncodingConversionAllowLossy|NSUTF8StringEncoding
                        error:nil];

NSMutableArray *itemsTMP = [[NSMutableArray alloc] init];

// Create parser for the api
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *results = [parser objectWithString:jsonString error:nil];

itemsTMP = [results objectForKey:@"results"];

[self setAllItems:[itemsTMP copy]];
self.displayItems = [itemsTMP copy];

int a =   [displayItems count];
    NSString *countString = [NSString stringWithFormat:@" results %d",a];
    countLabel.text = countString;

}

助けてくれてありがとう

4

3 に答える 3

1

AppleDeveloperツールの一部として利用できるInstrumentsツールを使用する必要があります。それはあなたが求めていることを正確に行うために、そして他の多くのことのために本当に素晴らしいです。ここから始めるのが良いでしょう:http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/Introduction/Introduction.html

于 2013-02-22T19:59:01.950 に答える
1

JSONをダウンロードする前に「タイムスタンプ」を取得してください

NSDate *startTime = [[NSDate alloc] init];

// Download the JSON
NSString *jsonString = [NSString
                        stringWithContentsOfURL:[NSURL URLWithString:queryLine]
                        encoding:NSStringEncodingConversionAllowLossy|NSUTF8StringEncoding
                        error:nil];

NSDate *elapsedTime = [NSDate dateWithTimeInterval:0 sinceDate:startTime];

経過時間は、日付から秒秒に設定されたNSDateオブジェクトになります。

于 2013-02-22T20:07:31.523 に答える
0

これは私が使用することになったものです。それは私のニーズにぴったりでした。

  NSLog(@"Begin <your method name>");
NSDate *startTime = [NSDate date];

// Do something useful here

NSTimeInterval elapsedTime = [startTime timeIntervalSinceNow];
NSLog(@"End <your method name>");
NSLog([NSString stringWithFormat:@"Elapsed time: %f", -elapsedTime]);
于 2013-02-24T12:05:05.453 に答える