Forum Discussion
How to calculate the time for running the code in Nios II and Nios V?
Hi,
How do I calculate the time used for executing a command in Nios II and Nios V.
I was using the example in the below link but the results from Nios II and Nios V are different.
https://cplusplus.com/reference/ctime/clock/
-------------------------------------------------------------------------------------------------------
clock_t t;
t = clock();
printf ("Calculating...\n");
... (Anything, or you may put usleep (1000000)
...
...
t = clock() - t;
printf ("It took me %ld clicks (%f seconds).\n",t,((float)t)/1000000);
printf ("It took me %u clicks (%x seconds).\n",t,((float)t)/1000000);
-------------------------------------------------------------------------------------------------------
Nios II
Nios V
Could you share the way to calculate the time taken for running a piece of code in Nios V?
Thanks
17 Replies
- ShengN_altera
Super Contributor
Hi,
I'm creating C++ Hello World executable project and replace the code with the one you stated. I'm getting the results for Nios II Eclipse IDE and Nios V RiscFree IDE as below:
Nios II Eclipse IDE (image):
Nios V RiscFree IDE (image):
Both are almost the same. RiscFree (42) seems like faster a bit than Eclipse (48). Check the attached file.
Best regards,
Sheng
p/s: If any answer from the community or Intel Support are helpful, please feel free to give best answer or rate 4/5 survey.
- ShengN_altera
Super Contributor
Hi @Chris039 ,
Do you still need further help on this thread?
Let me know if you have further concern or consideration.
Thanks,
Best Regards,
Sheng
p/s: If any answer from the community or Intel Support are helpful, please feel free to give best answer or rate 4/5 survey.
- Chris039
Occasional Contributor
Yes. Let me check the file and I will update again .
- Chris039
Occasional Contributor
I am not comparing the software tool. I was instantiating the Nios II processor and Nios V processor in Qsys, comparing both the time taken to execute the command.
- ShengN_altera
Super Contributor
Hi,
May be can refer to this link https://levelup.gitconnected.com/8-ways-to-measure-execution-time-in-c-c-48634458d0f9 on various ways of measuring cpu execution time. Or try to reprogram the software.
Thanks,
Best Regards,
Sheng
- Chris039
Occasional Contributor
Hi,
This is not related to reprogramming. Can you try to measure using the Nios V processor? You may generate the example design in https://www.intel.com/content/www/us/en/docs/programmable/726952/22-1-21-2-0/processor-example-design.html
- ShengN_altera
Super Contributor
Hi @Chris039 ,
I have done testing Nios V Hello World Example Design. I'm measuring the time taken for Nios V to run C++ code with looper and usleep(1000000) (code image below) and getting the results (image below):
Time taken: 16771 clicks (0.016771s)
Then I'm measuring the time taken for Nios V to run with only usleep(1000000) without looper (code image below) and getting the results (image below):
Time taken: 994 clicks (0.000994s). Close to your results.
Installed RAM: 16.0 GB
I think the execution time measuring code and your result are both valid.
Thanks,
Best regards,
Sheng
p/s: If any answer from the community or Intel Support are helpful, please feel free to give best answer or rate 4/5 survey.
- Chris039
Occasional Contributor
Let me try to run.
- ShengN_altera
Super Contributor
Hi @Chris039 ,
Do you have any further update or concern?
Let me know if there's any.
Thanks,
Best regards,
Sheng
p/s: If any answer from the community or Intel Support are helpful, please feel free to give best answer or rate 4/5 survey.
- Chris039
Occasional Contributor
Hi Sheng,
I tried running the second code that you have shared.
clock_t t;t = clock();
printf ("Calculating...\n");usleep(1000000);
printf ("Bye world...\n");
t = clock() - t;printf ("It took me %ld clicks (%f seconds).\n",t,((float)t)/1000000);
printf ("It took me %u clicks (%x seconds).\n",t,((float)t)/1000000);
Why is my value in the bracket has negative sign and different from yours?- Chris039
Occasional Contributor
If I would like to delay one second in the code? what is the value I should put in usleep ()?
- ShengN_altera
Super Contributor
Hi,
Have you include the related library?
usleep() is in microseconds so you have to put 1000000 for 1 second.
Thanks,
Best Regards,
Sheng