Skip to content

Instantly share code, notes, and snippets.

@toughrogrammer
Created April 21, 2015 13:59
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 toughrogrammer/3bea3deaf3e28cf7ff07 to your computer and use it in GitHub Desktop.
Save toughrogrammer/3bea3deaf3e28cf7ff07 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <limits.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#define Random0to1 ((double) rand() / (RAND_MAX)) + 1
#define ITERATION 100000000
double get_time_milli() {
struct timeval tv;
gettimeofday(&tv, NULL);
return (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000;
}
int main() {
double prev, curr;
prev = get_time_milli();
for( int i = 0; i < ITERATION; i ++ ) {
double x = Random0to1;
double y = Random0to1;
double rad = atan2(y, x);
}
curr = get_time_milli();
printf("atan2 : diff = %lf\n", curr - prev);
prev = get_time_milli();
for( int i = 0; i < ITERATION; i ++ ) {
double x = Random0to1;
double y = Random0to1;
// x축 증가하는 방향 단위 벡터와의 내적
double rad = acos(x / (1 * sqrt(pow(x, 2) + pow(y, 2))));
}
curr = get_time_milli();
printf("acos : diff = %lf\n", curr - prev);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment