c++ - Benchmarking math.h square root and Quake square root -


OK, I had a board and wondered how fast the number of mathematics is. (Crafted by CQ but made by SGI).

But it has ended for me in the world of misery.

I tried this on Mac first, where math will win hands on Windows every time, where the magical number is always won, but I think that all this is from my deep sleep.

  1. Compile on Mac with "G ++ - O" Sq_root sq_root_test.cpp "When the program is run, it takes approximately 15 seconds to complete. Compiling it in VS 2005 takes a second division. (Actually I had to compile it in debug to show some numbers)

  2. Benchmarking of my poor person? I'm stupid because I get 0.01 for Magic HT for Mathematics H and 0 (It can not be that it can be fast?)

I do not know that this is the case but Mac is Intel and the PC is AMD for what Mac H. sqroot Is Mac using the hardware?

I got the fast square root algorithm

  // sq_root_test.cpp #include & lt; iostream & gt; # include & lt; Math.h & gt; #include & lt; ctime & gt; boat invSqrt (float x) {union {float f; int i;} tmp; tmp.f = x; tmp.i = 0x5f375 9df - (tmpii > 1); float y = tmp.f; return y * (1.5 f - 0.5 f * x * y * y);} int main () {std :: clock_t start; //} std :: clock (); Std :: clock_t end; Float root; Int Entertainment = 99 99 99 999; // --- Route = 2.0 F; Start = std :: clock (); Std :: cout & lt; & Lt; "Math.h SqRoot:"; For (int m = 0; m & lt; iterations; m ++) {(float) (1.0 / sqrt (rootMe)); Rootmee ++; } End = std :: clock (); Std :: cout & lt; & Lt; (Difference (end, start)) & lt; & Lt; Std :: endl; // --- std :: cout & lt; & Lt; "Earthquake SqRoot:"; RootMe = 2.0f; Start = std :: clock (); (Int q = 0; q & lefthinum; ethernet; q ++) {invSqrt (root ME); Rootmee ++; } End = std :: clock (); Std :: cout & lt; & Lt; (Difference (end, start)) & lt; & Lt; Std :: endl; }  

There are several problems with your standard First of all, float from int to your benchmark Potentially expensive artists are included if you want to know what is the basic cost of the class, you should root the benchmark square, not datatype conversion

Secondly, your entire benchmark (and is ) may be compiler because there is no side effect in it. I do not use the returned value (or it is in unstable memory place Archive), so the compiler sees that it may leave the whole thing .

Here's a clue that you had to disable optimization, that means your benchmarking code is broken. Do not disable never optimization at any time during benchmarking. You want to know which version runs the fastest, you should test it under the terms that actually use it. If you were using square roots in the display-sensitive code, then you can enable optimization, so how it works without optimization is completely irrelevant.

In addition, you are not benchmarking the cost of square root computing, but if you want to know that the inversion square root is the fastest way to calculate the square root, then you 1.0 /...//> The code must be taken under the earthquake version. (And since the division is a very expensive operation, this can be a big difference in your results)

In the end, it will be worth pointing out that Carmax's small move is fast prepared on 12 year old computer It was done. Once you fix your benchmark, then you will know that it is no longer optimized because today's CPU is very fast in computing the roots of the "real" class.


Comments