# How to measure Cycles per Byte of an Algorithm?

I am trying to measure the cycles per byte for $\mathop{SHA-3}$ reference implementation. I am using recommendations from Microsoft querying the performance counter. As you can see in the first snippet, cycles are measured before converting into microseconds. My code looks like the following:

QueryPerformanceCounter(&StartingTime);
SHA3_256(K_OUT, K_IN, length);
QueryPerformanceCounter(&EndingTime);

printf("Elapsed ticks: %.20f \n", ElapsedMicroseconds.QuadPart / (float)(length));


But the results are definitively wrong. It is mostly something smaller than $0.9$. I would guess a value around $30$ Cycles per Byte. What am I doing wrong?

• This is borderline Off Topic (implementations details). I tried to edit it to make it inside the crypto.se scope. If you feel like it doesn't reflect what you want to ask, feel free to revert. – Biv Oct 30 '16 at 11:50
• Also note that QueryPerformanceFrequency(&Frequency); is useless in your case. – Biv Oct 30 '16 at 11:52

To perform a good check, please use a large number of iterations (i.e. a for loop) of calls to the cryptographic primitive with your specific data size. Then average these out.