Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <Foundation/Foundation.h>
- int main (int argc, char **argv)
- {
- @autoreleasepool {
- const NSUInteger iterations = 10000000;
- const NSUInteger variation = 10000000;
- NSMutableArray *original = [NSMutableArray arrayWithCapacity:iterations];
- for (NSUInteger i = 0; i < iterations; i++) {
- [original addObject:@(arc4random_uniform(variation))];
- }
- NSMutableArray *chunked = [NSMutableArray array];
- NSDate *start = [NSDate date];
- #define ARRAY
- #ifdef ARRAY
- NSArray *sorted = [original sortedArrayUsingSelector:@selector(compare:)];
- NSNumber *current = nil;
- for (NSNumber *number in sorted) {
- if (![number isEqual:current]) {
- [chunked addObject:[NSMutableArray arrayWithObject:number]];
- current = number;
- } else {
- [[chunked lastObject] addObject:number];
- }
- }
- #else
- NSCountedSet *countedSet = [[NSCountedSet alloc] initWithArray:original];
- for (NSNumber *number in countedSet) {
- NSMutableArray *chunk = [NSMutableArray array];
- NSUInteger count = [set countForObject:number];
- for (NSUInteger i = 0; i < count; i++) {
- [chunk addObject:number];
- }
- [chunked addObject:chunk];
- }
- [chunked sortUsingComparator:^(NSArray *a1, NSArray *a2) {
- return [a1[0] compare:a2[0]];
- }];
- #endif
- NSLog(@"Operation took %lf seconds.", [[NSDate date] timeIntervalSinceDate:start]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement