Solved

Measure execution cycles of a code..

Posted on 2000-03-10
7
346 Views
Last Modified: 2013-11-15
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
Comment
Question by:wayud
7 Comments
 
LVL 11

Expert Comment

by:alexo
Comment Utility
If you program under windows, check the following functions:
  QueryPerformanceCounter()
  QueryPerformanceFrequency()

0
 
LVL 11

Accepted Solution

by:
alexo earned 100 total points
Comment Utility
Otherwise, there are pentium-specific instructions that you may use to get high resolution timing.
Check RDTSC
0
 
LVL 3

Expert Comment

by:3rsrichard
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 30

Expert Comment

by:Zoppo
Comment Utility
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
 
LVL 5

Expert Comment

by:Wyn
Comment Utility
->If you program under windows, check the following functions:
  QueryPerformanceCounter()
  QueryPerformanceFrequency()
=================================
Fully agree.
0
 
LVL 32

Expert Comment

by:jhance
Comment Utility
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
 

Author Comment

by:wayud
Comment Utility
Thank you for all of you..
This is what I really need.
I'll try it now.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article shows how to convert a multi-page PDF file into multiple image files, with one image file created for each page of the PDF. It does this by utilizing an excellent, free software package called GraphicsMagick. The solution is amazingly s…
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
This video demonstrates how to use each tool, their shortcuts, where and when to use them, and how to use the keyboard to improve workflow.
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now