Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // floats: avg. 0.76 ms
- // doubles: avg. 0.70 ms
- #include <chrono>
- using std::chrono::time_point;
- using std::chrono::steady_clock;
- using std::chrono::duration_cast;
- using std::chrono::nanoseconds;
- inline float osqrt(float x) { return sqrtf(x); }
- inline double osqrt(double x) { return sqrt(x); }
- template<typename real> void test(const char* realname)
- {
- const int Iterations = 3500;
- const int ArraySize = 100000;
- real ary[ArraySize];
- real dummy = 0.0;
- for (int i = 0; i < ArraySize; i++)
- ary[i] = (real)rand();
- auto a = steady_clock::now();
- for (int it = 0; it < Iterations; it++)
- for (int i = 0; i < ArraySize; i++)
- {
- ary[i] = osqrt(ary[i]);
- dummy += ary[i];
- }
- auto dur = steady_clock::now() - a;
- printf("%ss: avg. %.2f ms\n", realname, (double)duration_cast<nanoseconds>(dur).count() / (double)Iterations * 1.0e-6, dummy);
- }
- int main(int argc, char* argv[])
- {
- test<float>("float");
- test<double>("double");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement