I am trying to compare the CPU cycle required for two encryption algorithms. One algorithm is AES and lets the other algorithm is B(code name). I implemented algorithm B and having fewer and simpler operations than AES and expected to take much less time/CPU cycles per encryption than AES
I am using an Intel i3, 10 gen processor, with 4MB cache. I am running both algorithms individually (with random 16-byte input) for $2^{20}$ times and taking the minimum and maximum required CPU cycles.
I see that for algorithm B CPU cycles are minimum=2707866
and maximum=4767402
. But, for crypto++ definition of AES, the CPU cycles are minimum=2724
and maximum=29978194
. I have performed the test multiple times and the results are almost similar. It is clear that the maximum time required for AES is much higher(7x) then algorithm B, but the minimum time for AES is much less.
I then recorded required CPU cycles for all $2^{20}$ AES encryption. I found that the first encryption is taking maximum cycles (29978194
) and then the required CPU cycle reduced drastically and after 10-15 encryption it took almost same(approx 3000
) CPU cycles for each encryption. For algorithm B every encryption took almost the same CPU cycles.
I do not understand the drastic reduction(10000 times) of CPU cycles for AES encryption(crypto++ library). Is there any voodoo of AES-NI? Can someone tell what kind of optimization is being done there?