Wednesday 15 July 2015

c++ - Timing operator+, operator-, operator*, and operator/ -


I have a simple mathematical vector class with an operated operator. I would like to get results for some time for my operators. I can easily take the time of my + =, - =, * =, and / = time with the following code:

  vector Zodiac; (Size_t i = 0; i & lt; iter; ++ i) yoga + = rand vector (); Cout & lt; & Lt; Amount & lt; & Lt; Endl;   

Then I can reduce the time it takes to generate time for random vectors. In my test, the vector is 3-dimensional, IARR = 10,000,000.

I tried this like +, -, *, /:

  vector zodiac; For (size_t i = 0; i   

Then make an array random vectors and subtract it while taking time to do it, although it gives "negative" time, to believe me that the compiler is optimizing the operation somehow , Or

I am using GAC-4.7.2 on a Fedora Linux machine.

Here is my timing code:

  clock_t start, k = clock (); Start = watch (); While (Start == K); F () (); Clock_t end = clock (); Double Time = Double (End-Start) / Double (CLOCKS_PER_SEC); Cout & lt; & Lt; Time - TIME_Iter_RAND_V - TIME_IR_SE;   

Here F is a function object that displays the above code. Time_Iter_Rand_V is that this time is for creating a random vector and time_ir_aas time was taken for the operation of the IT assignment.

My question is how to get the exact time of operator only + No assignment or random vector generation?

You can not really get the exact time for something when the optimization is on because of it That the compiler has the ability to move the code.

If you destabilize the time storage variable, then the situation is not subject to optimization due to the relative position of each other. However, the code is around them, as long as they are assigning or calling functions that include the Variable variables (this is a volatile member function that creates * this instability).

There are many weird things in code that you can optimize if you are expecting linear execution.

No comments:

Post a Comment