Solved

execution time of  a CODE??????

Posted on 2006-07-08
4
235 Views
Last Modified: 2012-05-05

Hi
I am studying computer architecture by my self  (distance learning). I am reading a book and found a question at the end about finding exceution time of code. The book does not explain this and there is no mention at all about this. With the following info can you obtain the execution time os a program:

-The number of cycles for each instruction.
-GH clock

so the question I need is a formula if there is one or how to calculate the execution time?
I hope you can help me.
Thanks a lot.

Jean
0
Comment
Question by:jean11
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 32

Assisted Solution

by:jhance
jhance earned 40 total points
ID: 17066516
In the old days (i.e. until the last few years) it was rather easy to determine how many clock cycles a program or a section of code would take.  CPU manufacturers published instruction sets and clock cycles/instruction and so all you had to do was add up the total and you had your answer.

Today, however, it's MUCH more complicated.  Modern processors use many techniques such as pipelining, speculative execution, branch prediction, multiple execution units, etc. as well as internal caches that make the prediction of execution time on an instruction-by-instruction basis very difficult if not impossible.  There is no longer a fixed relationship between an instruction and the number of clock cycles it takes.

What is done now is to look at execution at a macro level by using profiling tools.  These tools set hardware breakpoints at particular places in the code and then use timers to measure the execution time.  You can do a crude job of this yourself by using time functions in your code to keep track of execution times.
0
 

Author Comment

by:jean11
ID: 17066886
ok can explain more about calculating this in the old days?
What is the formula please?

add up the total of what?

thanks
0
 
LVL 70

Assisted Solution

by:garycase
garycase earned 40 total points
ID: 17066986
The concept is simple:   A program executes by executing a specific set of instructions.   If you know what all of these instructions are, and know how many clock cycles each of the instructions take;  you simply add up how many cycles it takes to fully execute the program -- and that tells you exactly how long it takes.   The "formula" is simply Execution Time = (time for instruction #1) + (time for instruction #2) + (time for instruction #3) + ...      Note that real-life programs have thousands (or even millions) of instructions !!

Simple concept -- not so simple to actually do, however:   When programs were MUCH smaller it wasn't so bad;  and in fact even as the programs grew a lot larger, there were tools that allowed the calculation to be automated  (Many good symbolic debuggers would execute a sequence of code, and keep track of the actual number of execution cycles the instructions required).

However ... as jhance noted, modern PC's now have much more complicated execution paths, which can allow more than one instruction to be executing at the same time;  and modern memory architectures do not require a fixed number of cycles to access an addressed memory element (is it in the cache?  ... if not is it the next reference from the last? ... if not then is it in the same bank as the last reference? ... etc. => each of these takes a different amount of time).   The result is a MUCH more complex process to definitively computer the boundaries of possible execution time.   It is still possible (and with the right debugging tools not too hard) to computer the "worst case" execution time -- all sequential execution;  no cached memory references;  but there is a fairly wide range of possibilities.   So, as jhance noted, the best approach is to use application profiling, where real-time measurements are made of the time a process starts and ends -- usually many times with an average execution time computed for the process.
0
 
LVL 11

Accepted Solution

by:
CarlosMMartins earned 45 total points
ID: 17089179
Pretty much covered, but I'l just add try and show a more "practical" side.

On simpler CPUs, you have a table showing how much cycles each instruction will take.
for example:

ADD Rn,Rm  (add two registers)                1 cycle
MOV Rn,Rm (move register to register)      1 cycle
MOV Rn,@addr (move register to memory) 3 cycles

You can then go through your routines and check how much time it will take to execute.
You also need to know the frequency of that instruction cycle, which is related to the CPU clock but might be different from it. Some CPUs have instruction cycles 1/2 or 1/4 of the input clock, others are 1:1, and others yet might even be faster 2x and 4x the input frequency.

On RISC architectures, most instructions take the same number of cycles (1 or 2).
On CISC architectures, execution time tens to vary a lot, having instructions that can take 2 cycles, and others that take dozens of cycles and more.

Some years ago I had to make a routine that had to execute in the same amount of time, no matter the execution flow, and I had to count those cycles, and insert NOPs in some IF branches, so it would always be in sync. :)
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
This paper addresses the security of Sennheiser DECT Contact Center and Office (CC&O) headsets. It describes the DECT security chain comprised of “Pairing”, “Per Call Authentication” and “Encryption”, which are all part of the standard DECT protocol.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

624 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