Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12589 Discussions

How to calculate the time for running the code in Nios II and Nios V?

Chris039
Novice
1,956 Views

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

Chris039_0-1668480322331.png

 

Nios V

Chris039_1-1668480353700.png

 

Could you share the way to calculate the time taken for running a piece of code in Nios V?

 

Thanks

 

 

0 Kudos
17 Replies
ShengN_Intel
Employee
1,933 Views

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):

2.PNG

Nios V RiscFree IDE (image):

1.PNG

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.

 

0 Kudos
ShengN_Intel
Employee
1,921 Views

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.

 

0 Kudos
Chris039
Novice
1,901 Views

Yes. Let me check the file and I will update again .

0 Kudos
Chris039
Novice
1,892 Views

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.

0 Kudos
ShengN_Intel
Employee
1,887 Views

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


0 Kudos
Chris039
Novice
1,879 Views

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

0 Kudos
ShengN_Intel
Employee
1,861 Views

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):

Capture1.PNGCapture.PNG

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):

Capture3.PNGCapture2.PNG

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.

 

0 Kudos
Chris039
Novice
1,850 Views

Let me try to run.

0 Kudos
ShengN_Intel
Employee
1,819 Views

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.

 

0 Kudos
Chris039
Novice
1,808 Views

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_0-1669606224603.png

 

 

 

0 Kudos
Chris039
Novice
1,808 Views

If I would like to delay one second in the code? what is the value I should put in usleep ()?

0 Kudos
ShengN_Intel
Employee
1,803 Views

Hi,


Have you include the related library?

usleep() is in microseconds so you have to put 1000000 for 1 second.


Thanks,

Best Regards,

Sheng


0 Kudos
Chris039
Novice
1,792 Views

Do you have the compilation result with the code above using Nios II processor?

0 Kudos
Chris039
Novice
1,728 Views

 

@ShengN_Intel  Any updates from your side?

0 Kudos
ShengN_Intel
Employee
1,722 Views

Hi @Chris039 ,

 

Still in the process of testing. Let me get back to you once getting the testing result.

 

Thanks,

Best Regards,

Sheng

 

0 Kudos
ShengN_Intel
Employee
1,706 Views

Hi @Chris039 ,

 

I tested the MAX 10 Nios II Hello World example in Intel FPGA Design Store. I found out for Nios II Interval Timer needs to be added in order to get accurate and valid execution time calculation. Also in BSP Editor, set the sys_clk_timer check image below:

Capture.PNGCapture1.PNGCapture2.PNG

The execution time of Nios II for running code without looper is 1427 clicks which is close to Nios V execution time of 997 clicks.

Folder attached below.

 

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.

 

0 Kudos
ShengN_Intel
Employee
1,673 Views

Hi @Chris039 ,

 

Do you have any further concern?

 

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.

 

0 Kudos
Reply