Skip to content

Instantly share code, notes, and snippets.

@eienf
Last active December 10, 2015 20:58
Show Gist options
  • Save eienf/4491286 to your computer and use it in GitHub Desktop.
Save eienf/4491286 to your computer and use it in GitHub Desktop.
Time measurement NSDateFormatter creation. Not Use ARC.
//
// main.m
// CodeTest
//
// Created by eien.support@gmail.com 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