Created
July 27, 2012 11:38
-
-
Save pieterjongsma/3187515 to your computer and use it in GitHub Desktop.
Parabolic Fit Test
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 "ParabolicFitTest.h" | |
@interface ParabolicFitTest () | |
- (NSInteger)functionOne:(NSInteger)index; | |
- (NSInteger)functionTwo:(NSInteger)index; | |
@end | |
@implementation ParabolicFitTest { | |
// Function variables | |
NSInteger _maxPeakHeight; | |
NSInteger _numberOfFrames; | |
} | |
- (id)init | |
{ | |
if ((self = [super init])) { | |
self.repetitions = 1000; // Default number of repetitions | |
_maxPeakHeight = 32768; | |
_numberOfFrames = 1000; | |
} | |
return self; | |
} | |
- (void)runBatch | |
{ | |
for (NSInteger r=0; r < self.repetitions; r++) { | |
[self runSingle]; | |
} | |
} | |
- (void)runSingle | |
{ | |
for (NSInteger i=0; i < _numberOfFrames; i++) { | |
[self functionOne:i]; | |
[self functionTwo:i]; | |
} | |
} | |
#pragma mark - Actual to-test functions | |
- (NSInteger)functionOne:(NSInteger)index | |
{ | |
NSInteger result = -(index - _numberOfFrames/2)^2 / (_numberOfFrames/2)^2*_maxPeakHeight + | |
_maxPeakHeight; | |
return result; | |
} | |
- (NSInteger)functionTwo:(NSInteger)index | |
{ | |
NSInteger result = sinf((float)index/_numberOfFrames*M_PI)*_maxPeakHeight; | |
return result; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment