Skip to content

Instantly share code, notes, and snippets.

@abel0b
Created February 1, 2020 16:10
Show Gist options
  • Save abel0b/772e22d0d22319093ce2e0d4f78f301d to your computer and use it in GitHub Desktop.
Save abel0b/772e22d0d22319093ce2e0d4f78f301d to your computer and use it in GitHub Desktop.
calculcate power 3/2
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <omp.h>
#define N 1000000
// Compare 3/2 power calculation
int main() {
float start, end;
int i;
int a = 42;
float ret;
start = omp_get_wtime();
for(i=0;i<N;i++) {
ret = pow(a, 3.0/2.0);
}
end = omp_get_wtime();
printf("POW: %f in %fs\n", ret, end-start);
start = omp_get_wtime();
for(i=0;i<N;i++) {
ret = sqrtf(a*a*a);
}
end = omp_get_wtime();
printf("SQRT: %f in %fs\n", ret, end-start);
return 0;
}

Compile

gcc -fopenmp -lm main.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment