atreat/NSString-Sha1 — pull request #3 by duedal (2013-01-14 09:11:03+00:00)
Title: Speed optimization

NSMutableString is somewhat slow, by replacing with a C-loop and single call to NSString's initWithBytesNoCopy:length:encoding:freeWhenDone: performance can be increased.

For 100,000 iterations on an iPad 3:

Original version: 8.880623 seconds
Optimized: 2.305083 seconds
An x3.8 improvement.

Tested with:
``` Obj-C
CFAbsoluteTime StartSlow = CFAbsoluteTimeGetCurrent();

for(NSUInteger i=0;i<100000;i++) {
[@"a" sha1slow];
}

dispatch_async(dispatch_get_main_queue(), ^{
dispatch_async(dispatch_get_main_queue(), ^{
CFTimeInterval endTime = CFAbsoluteTimeGetCurrent();
NSLog(@"Original took %f",endTime-StartSlow);
});
});

CFAbsoluteTime StartOptimized = CFAbsoluteTimeGetCurrent();

for(NSUInteger i=0;i<100000;i++) {
[@"a" sha1];
}

dispatch_async(dispatch_get_main_queue(), ^{
dispatch_async(dispatch_get_main_queue(), ^{
CFTimeInterval endTime = CFAbsoluteTimeGetCurrent();
NSLog(@"Optimized took %f",endTime-StartOptimized);
});
});
```