calculating execution time

C

Chris Dollin

Chris said:
Not at all. I can do it with relative ease for a PowerPC. You get the
timing not from the source code

Well, it's not a C question then, is it; it's a question about how
some (particular) C code is compiled on some (particular) platform.
but you use a sim or an ICE on the
compiled system and can time between points be they HLL or Assembler. OR
even accesses to a memory location.

Measurement and calculation are not the same thing.
The problem only arises if you have an OS on the target that is
non-determinisitc.

Or if the target itself is non-deterministic, or at least you don't
have access to the source of the apparent non-determinism: I'm
thinking vaguely of the ARM on-chip cache.
Many systems run apps without an OS so their run times with and without
interrupts can be easily and repeatabley determined.
Sure:

If you pick the situations where it's easy, it's easy.
Some run with derterministic RTOS and again timings can be obtained...

Its how we do real time systems

Yes. You do them by /arranging that it's possible/; by doing things that
aren't about C, but about the environment the code runs in and is created
by.

It's important, so you have to do it; but it's not the general case
(just as PCs and workstations aren't the general case).
 
G

Guru Jois

Guru Jois said:



Please learn C before trying to teach it. Your advice is incorrect and
unsound.


My all advice will be specific to C on Unix which is most common. If
OS is to be discussed proir to solution,
then its better to create a saperate group for C on Windows.
I also request you to point out where went wrong before declaring the
same.

Bye

Guru Jois
 
R

Richard Heathfield

Guru Jois said:
My all advice will be specific to C on Unix which is most common.

1) Here, we discuss C, not Unix.
2) Your advice is incorrect in Unix, too.
If
OS is to be discussed proir to solution,
then its better to create a saperate group for C on Windows.

There *are* separate groups for discussing Unix programming and Windows
programming. Here, we discuss C.
I also request you to point out where went wrong before declaring the
same.

For one thing, C has no CLOCKS_PER_SECOND identifier. For another,
neither clock() nor time() can help you to calculate run-time. The best
they can do is help you to measure it, and even then, you'd have to use
them fairly cleverly to get a good result, and you'd have to know what
sort of run-time you were trying to measure.
 
C

Clever Monkey

Richard said:
A good point. However if you said "I know the population of the Earth is
more than 1000 because more than 1000 go to see Chelsea every saturday"
then you have justified your claim.

Yeah, but does that never happen?
 
C

Clever Monkey

Richard said:
Guru Jois said:


1) Here, we discuss C, not Unix.
2) Your advice is incorrect in Unix, too.


There *are* separate groups for discussing Unix programming and Windows
programming. Here, we discuss C.


For one thing, C has no CLOCKS_PER_SECOND identifier. For another,
neither clock() nor time() can help you to calculate run-time. The best
they can do is help you to measure it, and even then, you'd have to use
them fairly cleverly to get a good result, and you'd have to know what
sort of run-time you were trying to measure.
One of the legacy code bases I maintain has a logging facility that can
be enabled with an environment variable. One of those variables will
enable prepending ticks since the last log message in front of each log
message.

We didn't care about things like CLOCKS_PER_SEC, &etc.

Probably not what the OP wants, since it is pretty rudimentary, but in
terms of helping me find places where things are slow (in shipped code
running on customer hardware) it has been invaluable.
 
J

Johan Bengtsson

Umesh said:
i want to calculate the time required to execute a program. Also i
want to calcute the time remaining for the execution of the program.
how can i do that?
If your program is doing some repetitive task and you know how many
repetitions it needs to do beforehand and it can be assumed that all
repetitions take approximately the same time (or the variations in
computing time can be calculated by some method) then it would be
possible to make a fair estimate of the remaining time by measuring time
from the beginning of the execution and doing this:

estimated_total = total_number_repetitions * measured_so_far /
repetitions_so_far;
time_remaining = estimated_total - measured_so_far;

This is how remaining time estimates for file copying and similar
operations are usually done.

This solution contains many ifs and the quality of the output might
range from "fairly good" to "completely worthless". Time estimates in
the beginning of such a run is usually quite close to "completely
worthless" but become gradually better.

As others have pointed out really there are many things in multitasking
operating systems with virtual memory and so on making time estimations
quite useless for short times. However those effects tend to average
them self out over a longer time. Operations taking several minutes or
more might be reasonably well estimated after a couple of minutes.
Note that the speed depends on processor speed, memory speed, hard disk
speed (especially if memory needs swapping), system load and a bunch of
other similar things.

If the task is not repetitive or if each repetition might take different
time to complete this method doesn't work well at all.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top