Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define NUMBER_OF_PARTICLES 1 << 15
- typedef struct _PARTICLE {
- float x;
- float y;
- float z;
- } PARTICLE;
- PARTICLE particles[NUMBER_OF_PARTICLES];
- void test1() {
- for (int i = 0; i < NUMBER_OF_PARTICLES; ++i) {
- PARTICLE particle = { 0, 0, 0 };
- for (int j = 0; j < NUMBER_OF_PARTICLES; ++j) {
- particle.x += particles[i].x + particles[j].x;
- particle.y += particles[i].y + particles[j].y;
- particle.z += particles[i].z + particles[j].z;
- }
- particles[i] = particle;
- }
- }
- void test2() {
- float X[NUMBER_OF_PARTICLES];
- float Y[NUMBER_OF_PARTICLES];
- float Z[NUMBER_OF_PARTICLES];
- for (int i = 0; i < NUMBER_OF_PARTICLES; ++i) {
- X[i] = particles[i].x;
- Y[i] = particles[i].y;
- Z[i] = particles[i].z;
- }
- for (int i = 0; i < NUMBER_OF_PARTICLES; ++i) {
- PARTICLE particle = { 0, 0, 0 };
- for (int j = 0; j < NUMBER_OF_PARTICLES; ++j) {
- particle.x += X[i] + X[j];
- particle.y += Y[i] + Y[j];
- particle.z += Z[i] + Z[j];
- }
- particles[i] = particle;
- }
- }
- int main(int argc, char** argv) {
- clock_t t1, t2;
- t1 = clock();
- test1();
- t2 = clock();
- printf("test1: %d\n", t2 - t1);
- t1 = clock();
- test2();
- t2 = clock();
- printf("test2: %d\n", t2 - t1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement