Solved

Measure execution cycles of a code..

Posted on 2000-03-10
7
353 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
ID: 2604570
If you program under windows, check the following functions:
  QueryPerformanceCounter()
  QueryPerformanceFrequency()

0
 
LVL 11

Accepted Solution

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

Expert Comment

by:3rsrichard
ID: 2604729
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 31

Expert Comment

by:Zoppo
ID: 2604951
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
ID: 2605210
->If you program under windows, check the following functions:
  QueryPerformanceCounter()
  QueryPerformanceFrequency()
=================================
Fully agree.
0
 
LVL 32

Expert Comment

by:jhance
ID: 2605249
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
ID: 2606973
Thank you for all of you..
This is what I really need.
I'll try it now.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Dropbox 3 79
All doc, xls, and pdf's are gone 9 88
Remote control for TV and internet recording 4 44
How does this program upload video to Youtube? 10 32
Today companies are subjected to more-and-more data, and it won't stop any time soon.  But there are obvious opportunities for reducing data, particularly data duplicated among companies.
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Using Adobe Premiere Pro, the viewer will learn how to set up a sequence with proper settings, importing pictures, rendering, and exporting the finished product.

813 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

10 Experts available now in Live!

Get 1:1 Help Now