I'm trying to test the cache property of a machine that has access to me I am trying to read the time.
Now the issue is that with the appropriate optimization level, GCC will optimize reading because it has no side effects, I can not have any optimization level Otherwise all loop variables will read the memory. I have tried some different things like unstable volatile, and using inline functions which are inserted as instability, but it is very difficult to estimate the treatment of the unstable variable of GCC. What is the proper way to do this? There is a possibility that using array data in a way can not be easily adapted away Such as If the testing function and the caller are both in the same compilation unit, it may also need to be sure that you actually do something with the returned time period, eg output it through printf . for clock1 = get_ticks () (for i = 0;) I look like this: I & lt; 1000000; I ++) {for (j = 0; j & lt; (workset * stride / size (data_t)); j + = stride) {* array [j]; }} Clock2 = get_ticks ()
clock1 = get_ticks (); Yoga = 0; (I = 0; i & lt; 1000000; i ++) {for (j = 0; j & lt; (workingset * stride / sizeof (data_t)); j + = stride) {sum + = array [ J]; }} Clock2 = get_ticks (); Refund Amount;
sum must be in a register, and add operation should not add anything to the loop time.
Comments
Post a Comment