Last active
December 19, 2015 16:14
-
-
Save ruleroller/f81dcd1f1fcfa5091640 to your computer and use it in GitHub Desktop.
get the time how the program it takes by second
This file contains 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
#import <Foundation/Foundation.h> | |
int main (int argc, const char * argv[]) { | |
@autoreleasepool { | |
// Read in files as large strings | |
NSString *nameList = [NSString stringWithContentsOfFile:@"/usr/share/dict/propernames" | |
encoding:NSUTF8StringEncoding | |
error:NULL]; | |
NSString *wordList = [NSString stringWithContentsOfFile:@"/usr/share/dict/words" | |
encoding:NSUTF8StringEncoding | |
error:NULL]; | |
// Break up lists into array of strings | |
NSArray *names = [nameList componentsSeparatedByString:@"\n"]; | |
NSArray *words = [wordList componentsSeparatedByString:@"\n"]; | |
int i = 0; | |
NSDate * startTime = [NSDate date]; | |
NSSet * wordsSet = [NSSet setWithArray:words]; | |
NSSet * namesSet = [NSSet setWithArray:names]; | |
for (NSString * name in namesSet) { | |
if ([wordsSet containsObject:name.lowercaseString] && ![name isEqualToString:@""]) { | |
i += 1; | |
} | |
} | |
NSDate * endTime = [NSDate date]; | |
double timeTaken = [endTime timeIntervalSinceDate:startTime]; | |
NSLog(@"Total Number of Matches: %d.\nComparison completed in %.2f seconds.", i, timeTaken); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment