Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timing Method in Examples gives Large Error - Code is faster than you might think. #6

Open
budnail opened this issue Dec 16, 2015 · 1 comment

Comments

@budnail
Copy link

budnail commented Dec 16, 2015

Not a big deal at all, but the method of timing the hash function also includes the time it takes to print the hash values. Typical code from examples below:


ms = micros(); // timing starts here
Sha256.initHmac(hmacKey1,20); // initialize and load the key - fair to include
Sha256.print("Hi There");// load the data - fair to include
printHash(Sha256.resultHmac()); //also includes time to serial print 32 hex characters
Serial.print(" Hash took : "); // includes time to print this label
Serial.print((micros() - ms)); // time calculated here
Serial.println(" micros");
Serial.println();


In one of my test cases, the time to perform the HMAC SHA256 was showing about 950 microseconds. After I reworked my code to not include the serial print, the time dropped to 344 microseconds. This time also included some code I added to convert the binary HMAC to Hex format.

I don't have a really good way to get accurate timing values that is worth sharing, but thought it might be a good idea to point this out for someone who might get discouraged on a slow processor. The code is much faster than the examples might indicate. Which is a good thing. I'm not suggesting that anything be changed unless there is a good place to add a note in the documentation.

@spaniakos
Copy link
Owner

You are right. I will rework some code in january, as until the 1st of
January i wont be able to test changes to the freamework. Also i will try
to make a unified hash/encryption library in order to have multiple choices.

Thanks for the remarks,
Spaniakos
On Dec 17, 2015 1:12 AM, "Bud Nail" [email protected] wrote:

Not a big deal at all, but the method of timing the hash function also
includes the time it takes to print the hash values. Typical code from

examples below:

ms = micros(); // timing starts here
Sha256.initHmac(hmacKey1,20); // initialize and load the key - fair to
include
Sha256.print("Hi There");// load the data - fair to include
printHash(Sha256.resultHmac()); //also includes time to serial print 32
hex characters
Serial.print(" Hash took : "); // includes time to print this label
Serial.print((micros() - ms)); // time calculated here
Serial.println(" micros");

Serial.println();

In one of my test cases, the time to perform the HMAC SHA256 was showing
about 950 microseconds. After I reworked my code to not include the serial
print, the time dropped to 344 microseconds. This time also included some
code I added to convert the binary HMAC to Hex format.

I don't have a really good way to get accurate timing values that is worth
sharing, but thought it might be a good idea to point this out for someone
who might get discouraged on a slow processor. The code is much faster than
the examples might indicate. Which is a good thing. I'm not suggesting that
anything be changed unless there is a good place to add a note in the
documentation.


Reply to this email directly or view it on GitHub
#6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants