0

I would like to know if there is an accurate way to compute the number of cycles needed to produce a certain amount of byte of a custom cryptographic algorithm. It seems that some libraries exist but it also seems quiet hard to add a new algorithm in it.

So far, I have read that the computation consists of running thousands of encryption, compute the average time of an encryption and by knowing the clock frequency of the processor, it is possible to compute the number cycles per bytes produced. I'm just wondering how good is this computation since the processor might be used for another program,etc.

Does someone have a suggestion about the way I can perform this measurement in the cleaner environment as possible ? Or does someone know an advice about the method itself ?

Thank you !

1 Answer 1

1

If you need accurate number of cycles you must take the algorithm, lookup the code generated, compare it with the instruction set of the processor you intend to run it on and calculate it from there. This is very tedious and error prone (think hyper-threading) and the result changes when you change the processor.

However you don't usually care about the exact number of cycles, but instead are interested in deciding if one solution is faster than another. To do this you can simply measure using the system clock how fast each run. Unless you run on a dedicated system, there will be other jobs in the background that will interfere with the measurement. If you run the benchmark multiple times and average you should be able to exclude most of these effects (unless you run on a really overloaded system). Another thing is that if the clock is a bit inaccurate, so if the run-time is very small you can't measure it accurately. To work around that you can run the solution more times. I.e. if you expect 1ms run-time, run it for 1000 times to get about 1 second.

So for most reliable result you should run the code many times (should take a few seconds) on a system with as little background processes as possible (ideally on a few similar system).

1
  • Thank you for your answer. I think I had almost the same solution in mind ! You are right about the analysis of the assembly code : this is not my goal and I only want to have an idea about which algorithm is the fastest one. Feb 1, 2016 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.