Last active
February 18, 2019 07:20
-
-
Save atom2ueki/a55cae24a9757fc4bf9b9efc5e74149d to your computer and use it in GitHub Desktop.
form an array of sqrt of float numbers from another float array by using accelerate vs forloop way
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> | |
#import <Accelerate/Accelerate.h> | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
NSLog(@"start"); | |
int count = 10000000; | |
float *x = malloc(count * sizeof(float)); | |
float initial = 0; | |
float increment = drand48()*count; | |
vDSP_vramp(&initial, &increment, x, 1, count); | |
float *y = malloc(count * sizeof(float)); | |
vvsqrtf(&*y, x, &count); | |
NSLog(@"number x: %f", x[100]); | |
NSLog(@"number y: %f", y[100]); | |
NSLog(@"end"); | |
} | |
return 0; | |
} |
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 { | |
NSLog(@"start"); | |
int count = 10000000; | |
float *x = malloc(count * sizeof(float)); | |
float initial = 0; | |
float increment = drand48()*count; | |
for (int i=0;i<count;i++) | |
{ | |
x[i] = initial + increment; | |
initial = x[i]; | |
} | |
float *y = malloc(count * sizeof(float)); | |
for (int i=0;i<count;i++) | |
{ | |
y[i] = sqrtf(x[i]); | |
} | |
NSLog(@"number x: %f", x[100]); | |
NSLog(@"number y: %f", y[100]); | |
NSLog(@"end"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment