Advertisement
Guest User

atan2 vs acos benchmark

a guest
Sep 30th, 2010
841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <cstdlib>
  5.  
  6. #include "TimeET.h"
  7. // TimeET from Tekkotsu library:
  8. // http://hg.tekkotsu.org/Tekkotsu/raw-file/tip/Shared/TimeET.h
  9. // http://hg.tekkotsu.org/Tekkotsu/raw-file/tip/Shared/TimeET.cc
  10.  
  11. using namespace std;
  12. float randf() { return random()/(float)((1U<<31)-1); }
  13.  
  14. int main(int argc, char** argv) {
  15.     const size_t COUNT=1<<25;
  16.     vector<float> n(COUNT+1);
  17.     for(size_t i=0; i<COUNT+1; ++i)
  18.         n[i]=randf()*2*M_PI-M_PI;
  19.    
  20.     vector<float> o(COUNT);
  21.     TimeET ot;
  22.     for(size_t i=0; i<COUNT; ++i)
  23.         o[i] = 0;
  24.     ot=ot.Age();
  25.     cout << "overhead: " << ot.Value()/COUNT*1e9 << endl;  
  26.    
  27.     vector<float> r1(COUNT);
  28.     TimeET at2;
  29.     for(size_t i=0; i<COUNT; ++i)
  30.         r1[i] = atan2(n[i],n[i+1]);
  31.     cout << "atan2: " << (at2.Age()-ot).Value()/COUNT*1e9 << endl;
  32.  
  33.     vector<float> r2(COUNT);
  34.     TimeET ac;
  35.     for(size_t i=0; i<COUNT; ++i)
  36.         r2[i] = acos(n[i]);
  37.     cout << "acos: " << (ac.Age()-ot).Value()/COUNT*1e9 << endl;
  38.    
  39.     vector<float> r3(COUNT);
  40.     TimeET acd;
  41.     for(size_t i=0; i<COUNT; ++i)
  42.         r3[i] = acos(n[i]/n[i+1]);
  43.     cout << "acos/: " << (acd.Age()-ot).Value()/COUNT*1e9 << endl;
  44.    
  45.     vector<float> r4(COUNT);
  46.     TimeET at;
  47.     for(size_t i=0; i<COUNT; ++i)
  48.         r4[i] = atan(n[i]);
  49.     cout << "atan: " << (at.Age()-ot).Value()/COUNT*1e9 << endl;
  50.    
  51.     vector<float> r5(COUNT);
  52.     TimeET atd;
  53.     for(size_t i=0; i<COUNT; ++i)
  54.         r5[i] = atan(n[i]/n[i+1]);
  55.     cout << "atan/: " << (atd.Age()-ot).Value()/COUNT*1e9 << endl;
  56.    
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement