• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 376
  • Last Modified:

Measure execution cycles of a code..

I am now writing a code in C.
I want to measure execution speed of a code for as high resolution as possible.
I've tried to read PC timer (mc146818) datasheet, its registers can only give 1 second resolution.
Interrupt 1A can only gives 1/100 second resolution.
If it is possible, I want to get the result as a number of clock cycles.
Anybody can point me out about this?

Thanks,
0
wayud
Asked:
wayud
1 Solution
 
alexoCommented:
If you program under windows, check the following functions:
  QueryPerformanceCounter()
  QueryPerformanceFrequency()

0
 
alexoCommented:
Otherwise, there are pentium-specific instructions that you may use to get high resolution timing.
Check RDTSC
0
 
3rsrichardCommented:
I can suggest two possible solutions
1) If you can run your program on a machine using Windows NT you can use the Administrative Tools - Performance Monitor to get something related to what you want.

The problem with trying to use the hardware timers is that the answer you get will be based on a specific set of hardware.  Another approach is to compile the code, get a listing, and count the number of instructions being executed.  Or if you have a debugger which keeps track of the number of lines executed that would do it.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
ZoppoCommented:
Hi wayud,

Have you tried 'clock'? It's resolution seems to be at least 20ms. Use it like this:

#include <time.h>

clock_t end, start = clock();
// do lengthy processing
end = clock();

hope that helps,

ZOPPO
0
 
WynCommented:
->If you program under windows, check the following functions:
  QueryPerformanceCounter()
  QueryPerformanceFrequency()
=================================
Fully agree.
0
 
jhanceCommented:
Another approach is to run the instructions in question 10, 100, 1000, etc. times (whatever is needed to get a meaningful result with the timer available) and then scale the result.
0
 
wayudAuthor Commented:
Thank you for all of you..
This is what I really need.
I'll try it now.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now