Skip to content

Instantly share code, notes, and snippets.

@valexey
Created January 19, 2018 15:50
Show Gist options
  • Save valexey/8d9596efe6626fe2118a2f67a221f301 to your computer and use it in GitHub Desktop.
Save valexey/8d9596efe6626fe2118a2f67a221f301 to your computer and use it in GitHub Desktop.
#include <math.h>
#include <stdio.h>
float some = 0.0;
struct Foo {
float x[2];
//char name[1024*16];
float res;
//char name[1024*16];
Foo() : x{some, some}, res{0} {some += 3.1415;}
void scale(float s) {
float dx = sqrtf(x[0]*x[0]+x[1]*x[1]);
res += dx*s;
}
};
struct UpFoo {
float res;
};
void scale(Foo* f, float s) {
float dx = sqrtf(f->x[0]*f->x[0]+f->x[1]*f->x[1]);
f->res += dx*s;
}
void update(Foo* foos, UpFoo* upfoos, int len, float some) {
for (int i=0; i<len; ++i) {
float m = sqrtf(foos[i].x[0]*foos[i].x[0] + foos[i].x[1]+foos[i].x[1]);
upfoos[i].res = foos[i].res + m*some;
}
}
int main() {
const int len = 1024;
printf("--\n");
Foo* foos = new Foo[len];
UpFoo* upfoos = new UpFoo[len];
// for (int j=0; j<100000; j++)
// for (int i=0; i<len; ++i)
// //foos[i].scale(some);
// scale(&(foos[i]), some);
printf("-\n");
for (int j=0; j<100000; j++)
update(foos, upfoos, len, some);
// for (int i=0; i<len; ++i)
// printf("%f\n", foos[i].res);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment