counting time

Hello every one , I am making a project that encryption and decryption
my supervisor asked me to add a counter to the code so it can calculate time with encryption and without encryption

I searched and some says add this code int send_time = millis();

.....

int receive_time = millis();

int elapse_time = receive_time - send_time; // millisecond

but I don't know where to add it
if any one can guide me please

You should add it into your code somewhere. If you post your existing code here then it may be possible to offer more detailed help.

Steve

Oi! Add the code between lines 30098 and 30099 is as good a guess as anyone else might give; without seeing your code. Yuppers, no well formatted code in code tags, it's all just a guess. Good luck with that.

millis() is simply just the time "now" in milliseconds, since the system fired up.

Think about it...

The line:

int send_time=millis();

... captures the current time into a variable called "send_time".

Then, a while later the line:

int receive_time=millis();

... captures the new current time into another variable "receive_time".

Then it calculates the difference.

So why don't you have a think about where you would put that from a logical point of view? I'd imagine that if you have written code to encrypt and decrypt, adding a few lines to code would be relatively easy?

I didn't write the code , I am new to Arduino IDE

Note: The value returned by millis() is 'unsigned long int', not 'int'. Unless the encryption is VERY slow or you have a large quantity of data you might need to switch to micros() (microseconds) for timing.

If your 'send' and 'receive' are on different devices (implied by being separate sketches) then there is no way to subtract receive_time from send_time. You probably want the time before and after encryption and the time before and after decryption so you can tell how much overhead is in the encryption library.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.