Last active
December 10, 2015 20:58
-
-
Save eienf/4491286 to your computer and use it in GitHub Desktop.
Time measurement NSDateFormatter creation.
Not Use ARC.
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
// | |
// main.m | |
// CodeTest | |
// | |
// Created by [email protected] on 2013/01/09. | |
// Copyright (c) 2013 Eien Factory. All rights reserved. | |
// | |
// ARC=OFF | |
#import <Foundation/Foundation.h> | |
#import <mach/mach_time.h> | |
#define TEST 4 | |
int main(int argc, const char * argv[]) | |
{ | |
NSString *aString; | |
NSDateFormatter *dateFormatter; | |
NSDate *aDate; | |
@autoreleasepool { | |
uint64_t start, elapsed; | |
mach_timebase_info_data_t base; | |
mach_timebase_info(&base); | |
aDate = [NSDate date]; | |
start = mach_absolute_time(); | |
#if TEST==1 | |
//time = 10235446(nsec) | |
dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; | |
dateFormatter.dateFormat = @"y/M/d HH:mm:ss"; | |
for ( int i = 0; i < 1000; i++ ) { | |
aString = [dateFormatter stringFromDate:aDate]; | |
} | |
#elif TEST==2 | |
//time = 11717976(nsec) | |
dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; | |
for ( int i = 0; i < 1000; i++ ) { | |
dateFormatter.dateFormat = @"y/M/d HH:mm:ss"; | |
aString = [dateFormatter stringFromDate:aDate]; | |
} | |
#elif TEST==3 | |
//time = 152146810(nsec) | |
for ( int i = 0; i < 1000; i++ ) { | |
dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; | |
dateFormatter.dateFormat = @"y/M/d HH:mm:ss"; | |
aString = [dateFormatter stringFromDate:aDate]; | |
} | |
#elif TEST==4 | |
//time = 149760378(nsec) | |
for ( int i = 0; i < 1000; i++ ) { | |
dateFormatter = [[NSDateFormatter alloc] init]; | |
dateFormatter.dateFormat = @"y/M/d HH:mm:ss"; | |
aString = [dateFormatter stringFromDate:aDate]; | |
[dateFormatter release]; | |
} | |
#endif | |
elapsed = mach_absolute_time() - start; | |
uint64_t nsec = elapsed * base.numer / base.denom; | |
printf("time = %lld(nsec)\n",nsec); | |
NSLog(@"%@",aString); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment