468,545 Members | 1,718 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,545 developers. It's quick & easy.

calculating execution time

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?

pl mention some good websites for learning advanced C.thx.

Jun 5 '07 #1
25 4632
Umesh wrote:
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?
With a calculator?

--
Ian Collins.
Jun 5 '07 #2
On 5 Jun, 08:39, Ian Collins <ian-n...@hotmail.comwrote:
Umesh wrote:
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?

With a calculator?

--
Ian Collins.
I think this is not far from feeding a troll...

Jun 5 '07 #3
ma**********@pobox.com wrote:
On 5 Jun, 08:39, Ian Collins <ian-n...@hotmail.comwrote:
>Umesh wrote:
>>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?
With a calculator?

--
Ian Collins.

I think this is not far from feeding a troll...
It is, but it's been a quiet evening!

--
Ian Collins.
Jun 5 '07 #4
On Jun 4, 11:33 pm, Umesh <fraternitydispo...@gmail.comwrote:
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?
In C program, read help/man page for clock(), time() and
CLOCKS_PER_SECOND

On Unix box, use 'time' <commandto find how mush time the system
takes to execute it.
pl mention some good websites for learning advanced C.thx.
Google "advanced C guide" and follow the links.

Bye

Guru Jois

Jun 5 '07 #5
"Umesh" writes:
>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?
To calculate means to take some known facts, do some mathematical operations
on them and reach a numerical answer. IOW it is not the same as "measure".
Calculating execution time has always been difficult; with a modern desktop
system with virtual this and virtual that and L2 caches and advanced math
co-processors I would estimate the difficulty as somewhere between "don't
even try" and "impossible. I would doubt if there were even a handful of
people in the *world* who could do that and get a meaningful answer. And
those people work at Intel or AMD or some similar place. They are *not* the
people who used to write all these processor comparisons that used to be so
popular. I have seen good, competent people get answers that weren't even
in the ballpark. If you persist, the place to start would be an Intel site
or a site that provided the chip family you will be using.
Jun 5 '07 #6
In article <11**********************@o11g2000prd.googlegroups .com>,
Umesh <fr****************@gmail.comwrites
>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?

pl mention some good websites for learning advanced C.thx.
This is usually very easy to do BUT in all cases it is going to be VERY
platform specific.

What is the target system the app will be running on and do you have an
ICE for it?
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Jun 5 '07 #7
Guru Jois said:
On Jun 4, 11:33 pm, Umesh <fraternitydispo...@gmail.comwrote:
>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?
In C program, read help/man page for clock(), time() and
CLOCKS_PER_SECOND
Please learn C before trying to teach it. Your advice is incorrect and
unsound.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jun 5 '07 #8
Richard Heathfield <rj*@see.sig.invalidwrites:
Guru Jois said:
>On Jun 4, 11:33 pm, Umesh <fraternitydispo...@gmail.comwrote:
>>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?
In C program, read help/man page for clock(), time() and
CLOCKS_PER_SECOND

Please learn C before trying to teach it. Your advice is incorrect and
unsound.
If you know this advice to be incorrect then I guess you know the
correct answer?
Jun 5 '07 #9
osmium said:
Calculating execution time has always been difficult; with
a modern desktop system with virtual this and virtual that and L2
caches and advanced math co-processors I would estimate the
difficulty as somewhere between "don't even try" and "impossible. I
would doubt if there were even a handful of people in the *world* who
could do that and get a meaningful answer.
And those people work at Intel or AMD or some similar place.
Well, we know they don't work at Redmond.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jun 5 '07 #10
Richard said:
Richard Heathfield <rj*@see.sig.invalidwrites:
>Guru Jois said:
>>On Jun 4, 11:33 pm, Umesh <fraternitydispo...@gmail.comwrote:
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?

In C program, read help/man page for clock(), time() and
CLOCKS_PER_SECOND

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

If you know this advice to be incorrect then I guess you know the
correct answer?
It doesn't follow. For example, if someone says the population of the
planet is 1000, I know that's wrong. That doesn't mean I know the
correct figure. I just know it's a lot bigger than 1000.

Likewise, I know that you won't be able to calculate the execution time
of a program using clock(), time(), or the undefined identifier
CLOCKS_PER_SECOND. The fact that I know this doesn't imply that I have
a foolproof algorithm for calculating runtime.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jun 5 '07 #11
On Jun 5, 2:33 am, Umesh <fraternitydispo...@gmail.comwrote:
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?
I suggest that you google on the phrase "halting problem" and check
out a few of the references. I know that you'll find your answer
there, assuming that you recognize it.
Jun 5 '07 #12
osmium wrote:
Calculating execution time has always been difficult; with a modern desktop
system with virtual this and virtual that and L2 caches and advanced math
co-processors I would estimate the difficulty as somewhere between "don't
even try" and "impossible. I would doubt if there were even a handful of
people in the *world* who could do that and get a meaningful answer.
OTOH, calculating run time on an 8051, PIC, AVR, MSP430, or similiar
low-end micro is straight-forward. It is not uncommon to see
documentation giving the execution time of a routine in clock cycles,
usually for code written in assembly language.

--
Thad
Jun 5 '07 #13
In article <5c*************@mid.individual.net>, osmium
<r1********@comcast.netwrites
>"Umesh" writes:
>>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?

To calculate means to take some known facts, do some mathematical operations
on them and reach a numerical answer. IOW it is not the same as "measure".
Calculating execution time has always been difficult; with a modern desktop
system
You mean it is difficult to calculate the execution time for apps on a
modern desk top system.

I use a modern desktop system to give me cycle accurate timings. The
problem is the OP needs to supply more information, starting what the
target platform is.
>with virtual this and virtual that and L2 caches and advanced math
co-processors I would estimate the difficulty as somewhere between "don't
even try" and "impossible.
For a PC app I would agree
I would doubt if there were even a handful of
people in the *world* who could do that and get a meaningful answer. And
those people work at Intel or AMD or some similar place.
They can't do it... they will have the same problems as anyone else in
the case you are suggesting. Ie an app running on a PC of unknown MCU
type and a version of Windows with other programms/dlls ec also
running.
They are *not* the
people who used to write all these processor comparisons that used to be so
popular. I have seen good, competent people get answers that weren't even
in the ballpark. If you persist, the place to start would be an Intel site
or a site that provided the chip family you will be using.
Not at all. This is quite pointless.. You have not ascertained he is
even running on x86 architecture yet!

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Jun 5 '07 #14
In article <46***********************@auth.newsreader.octanew s.com>,
Thad Smith <Th*******@acm.orgwrites
>osmium wrote:
>Calculating execution time has always been difficult; with a modern
desktop system with virtual this and virtual that and L2 caches and
advanced math co-processors I would estimate the difficulty as
somewhere between "don't even try" and "impossible. I would doubt if
there were even a handful of people in the *world* who could do that
and get a meaningful answer.

OTOH, calculating run time on an 8051, PIC, AVR, MSP430, or similiar
low-end micro is straight-forward.
Or most medium and high end MCU..... depending on if you are running no
Os, and RTOS or an OS
It is not uncommon to see documentation giving the execution time of a
routine in clock cycles, usually for code written in assembly language.
You can also time to the cycle HLL coded systems as well. I have often
don it with an ICE.

The problem we have is the vast majority on this NG have no experience
outside PC's using Windows or Linux and some will have used Unix. those
who have experience outside that narrow range seem few and far between
around here.

This was obvious when some said a map file would not contain exact
addresses of variables :- )
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Jun 5 '07 #15
Richard Heathfield <rj*@see.sig.invalidwrites:
Richard said:
>Richard Heathfield <rj*@see.sig.invalidwrites:
>>Guru Jois said:

On Jun 4, 11:33 pm, Umesh <fraternitydispo...@gmail.comwrote:
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?
>
In C program, read help/man page for clock(), time() and
CLOCKS_PER_SECOND

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

If you know this advice to be incorrect then I guess you know the
correct answer?

It doesn't follow. For example, if someone says the population of the
planet is 1000, I know that's wrong. That doesn't mean I know the
correct figure. I just know it's a lot bigger than 1000.

Likewise, I know that you won't be able to calculate the execution time
of a program using clock(), time(), or the undefined identifier
CLOCKS_PER_SECOND. The fact that I know this doesn't imply that I have
a foolproof algorithm for calculating runtime.
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.
Jun 5 '07 #16
Chris Hills wrote:
You mean it is difficult to calculate the execution time for apps on a
modern desk top system.
Was it easier on a VAX?
I use a modern desktop system to give me cycle accurate timings. The
problem is the OP needs to supply more information, starting what the
target platform is.
That's always been true, yes.

--
"It was the first really clever thing the King had said that day."
/Alice in Wonderland/

Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England

Jun 5 '07 #17
In article <f4**********@murdoch.hpl.hp.com>, Chris Dollin
<ch**********@hp.comwrites
>Chris Hills wrote:
>You mean it is difficult to calculate the execution time for apps on a
modern desk top system.

Was it easier on a VAX?
No idea but there are a hell of a Lot more platforms than a VAX and a
PC.
>I use a modern desktop system to give me cycle accurate timings. The
problem is the OP needs to supply more information, starting what the
target platform is.

That's always been true, yes.
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Jun 5 '07 #18
Chris Hills wrote:
In article <f4**********@murdoch.hpl.hp.com>, Chris Dollin
<ch**********@hp.comwrites
>>Chris Hills wrote:
>>You mean it is difficult to calculate the execution time for apps on a
modern desk top system.

Was it easier on a VAX?

No idea but there are a hell of a Lot more platforms than a VAX and a
PC.
I don't doubt it, but it means your restriction to "modern" above is
an over-simplification.

I think the rule of thumb to use is that calculating the execution
time of (any part of) an app, given it's C source, isn't easy unless
it happens -- through some coincidence of compiler transparency and
processor simplicity -- to be easy.

One should not expect it to be easy, although if one needs to do the sums
and it /is/ easy, much joy. The details are of course atopical here.

--
"It is seldom good news." ~Crystal Ball~, /The Tough Guide to Fantasyland/

Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England

Jun 5 '07 #19
In article <f4**********@murdoch.hpl.hp.com>, Chris Dollin
<ch**********@hp.comwrites
>Chris Hills wrote:
>In article <f4**********@murdoch.hpl.hp.com>, Chris Dollin
<ch**********@hp.comwrites
>>>Chris Hills wrote:

You mean it is difficult to calculate the execution time for apps on a
modern desk top system.

Was it easier on a VAX?

No idea but there are a hell of a Lot more platforms than a VAX and a
PC.

I don't doubt it, but it means your restriction to "modern" above is
an over-simplification.

I think the rule of thumb to use is that calculating the execution
time of (any part of) an app, given it's C source, isn't easy unless
it happens -- through some coincidence of compiler transparency and
processor simplicity -- to be easy.
Not at all. I can do it with relative ease for a PowerPC. You get the
timing not from the source code 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.

The problem only arises if you have an OS on the target that is
non-determinisitc.

Many systems run apps without an OS so their run times with and without
interrupts can be easily and repeatabley determined.

Some run with derterministic RTOS and again timings can be obtained...

Its how we do real time systems
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Jun 5 '07 #20
Chris Hills wrote:
In article <f4**********@murdoch.hpl.hp.com>, Chris Dollin
<ch**********@hp.comwrites
>>Chris Hills wrote:
>>In article <f4**********@murdoch.hpl.hp.com>, Chris Dollin
<ch**********@hp.comwrites
Chris Hills wrote:

You mean it is difficult to calculate the execution time for apps on a
modern desk top system.

Was it easier on a VAX?

No idea but there are a hell of a Lot more platforms than a VAX and a
PC.

I don't doubt it, but it means your restriction to "modern" above is
an over-simplification.

I think the rule of thumb to use is that calculating the execution
time of (any part of) an app, given it's C source, isn't easy unless
it happens -- through some coincidence of compiler transparency and
processor simplicity -- to be easy.

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:
>unless
it happens -- through some coincidence of compiler transparency and
processor simplicity -- to be easy.
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).

--
"You've spotted a flaw in my thinking, Trev" Big Al,/The Beiderbeck Connection/

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

Jun 6 '07 #21
On Jun 5, 5:21 am, Richard Heathfield <r...@see.sig.invalidwrote:
Guru Jois said:
On Jun 4, 11:33 pm, Umesh <fraternitydispo...@gmail.comwrote:
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?
In C program, read help/man page for clock(), time() and
CLOCKS_PER_SECOND

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

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999http://www.cpax.org.uk
email: rjh at the above domain, - www.

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

Jun 6 '07 #22
Guru Jois said:
On Jun 5, 5:21 am, Richard Heathfield <r...@see.sig.invalidwrote:
>Guru Jois said:
On Jun 4, 11:33 pm, Umesh <fraternitydispo...@gmail.comwrote:
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?
In C program, read help/man page for clock(), time() and
CLOCKS_PER_SECOND

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.
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.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jun 6 '07 #23
Richard wrote:
Richard Heathfield <rj*@see.sig.invalidwrites:
>Richard said:
>>Richard Heathfield <rj*@see.sig.invalidwrites:

Guru Jois said:

On Jun 4, 11:33 pm, Umesh <fraternitydispo...@gmail.comwrote:
>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?
>>
In C program, read help/man page for clock(), time() and
CLOCKS_PER_SECOND
Please learn C before trying to teach it. Your advice is incorrect
and unsound.
If you know this advice to be incorrect then I guess you know the
correct answer?
It doesn't follow. For example, if someone says the population of the
planet is 1000, I know that's wrong. That doesn't mean I know the
correct figure. I just know it's a lot bigger than 1000.

Likewise, I know that you won't be able to calculate the execution time
of a program using clock(), time(), or the undefined identifier
CLOCKS_PER_SECOND. The fact that I know this doesn't imply that I have
a foolproof algorithm for calculating runtime.

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?

--
clvrmnky <mailto:sp******@clevermonkey.org>

Direct replies will be blacklisted. Replace "spamtrap" with my name to
contact me directly.
Jun 6 '07 #24
Richard Heathfield wrote:
Guru Jois said:
>On Jun 5, 5:21 am, Richard Heathfield <r...@see.sig.invalidwrote:
>>Guru Jois said:

On Jun 4, 11:33 pm, Umesh <fraternitydispo...@gmail.comwrote:
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?
In C program, read help/man page for clock(), time() and
CLOCKS_PER_SECOND
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.

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.
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.
--
clvrmnky <mailto:sp******@clevermonkey.org>

Direct replies will be blacklisted. Replace "spamtrap" with my name to
contact me directly.
Jun 6 '07 #25
Umesh wrote:
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.
Jun 7 '07 #26

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Steve Amey | last post: by
2 posts views Thread by Eric Whittaker | last post: by
1 post views Thread by jlm | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.