Skip to content

Instantly share code, notes, and snippets.

@atom2ueki
Last active February 18, 2019 07:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atom2ueki/a55cae24a9757fc4bf9b9efc5e74149d to your computer and use it in GitHub Desktop.
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
#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;
}
#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