Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 86 lines (70 sloc) 2.587 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
#import "WorkerThread.h"
#include <sys/time.h>


@implementation WorkerThread

- (id)init {
self = [super init];
if (self != nil) {
m_formatterType = NoNSDateFormatter;
m_syncObject = nil;
m_syncFunction = nil;
m_worker = nil;
m_sum = 0;
m_numWorkers = 200;
}
return self;
}

- (id)initWithDateFormatter:(FormatterType)formatterType andSyncObject:(id)syncObject andSyncFunction:(SEL)syncFunction {
self = [self init];
if (self != nil) {
m_formatterType = formatterType;
m_syncObject = syncObject;
m_syncFunction = syncFunction;
}
return self;
}

- (void)main {

BOOL done = NO;

if (!m_worker)
m_worker = [[Worker alloc] init];


switch (m_formatterType) {
case NoNSDateFormatter:
for (int i = 0; i < m_numWorkers; ++i) {
double start = ({struct timeval v; gettimeofday(&v, NULL); (double)(v.tv_sec*1000.+v.tv_usec*0.001);});
done = [m_worker workWithoutDateFormater];
double stop = ({struct timeval v; gettimeofday(&v, NULL); (double)(v.tv_sec*1000.+v.tv_usec*0.001);});
m_sum += stop - start;
}
break;

case NSDateFormatterInit:
for (int i = 0; i < m_numWorkers; ++i) {
double start = ({struct timeval v; gettimeofday(&v, NULL); (double)(v.tv_sec*1000.+v.tv_usec*0.001);});
done = [m_worker workWithDateFormatterInit];
double stop = ({struct timeval v; gettimeofday(&v, NULL); (double)(v.tv_sec*1000.+v.tv_usec*0.001);});
m_sum += stop - start;
}
break;

case NSDateFormatterInitWithDateFormat10_0:
for (int i = 0; i < m_numWorkers; ++i) {
double start = ({struct timeval v; gettimeofday(&v, NULL); (double)(v.tv_sec*1000.+v.tv_usec*0.001);});
done = [m_worker workWithDateFormaterWithFormatterBehavior10_0];
double stop = ({struct timeval v; gettimeofday(&v, NULL); (double)(v.tv_sec*1000.+v.tv_usec*0.001);});
m_sum += stop - start;
}
break;

case NSDateFormatterInitWithDateFormat10_4:
for (int i = 0; i < m_numWorkers; ++i) {
double start = ({struct timeval v; gettimeofday(&v, NULL); (double)(v.tv_sec*1000.+v.tv_usec*0.001);});
done = [m_worker workWithDateFormaterWithFormatterBehavior10_4];
double stop = ({struct timeval v; gettimeofday(&v, NULL); (double)(v.tv_sec*1000.+v.tv_usec*0.001);});
m_sum += stop - start;
}
break;

default:
break;
}

printf("Thread %d: Time around = %f sec\n", [self.name intValue], m_sum * 0.001);
printf("Thread %d: Time inside = %f sec\n", [self.name intValue], m_worker.sum * 0.001);

if (done)
[m_syncObject performSelector:m_syncFunction withObject:[self name]];
}

@end
Something went wrong with that request. Please try again.