calculating execution time

Discussion in 'C Programming' started by Umesh, Jun 5, 2007.

  1. Umesh

    Umesh Guest

    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.
     
    Umesh, Jun 5, 2007
    #1
    1. Advertising

  2. Umesh

    Ian Collins Guest

    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.
     
    Ian Collins, Jun 5, 2007
    #2
    1. Advertising

  3. Umesh

    Guest

    On 5 Jun, 08:39, Ian Collins <> wrote:
    > 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, 2007
    #3
  4. Umesh

    Ian Collins Guest

    wrote:
    > On 5 Jun, 08:39, Ian Collins <> wrote:
    >> 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.
     
    Ian Collins, Jun 5, 2007
    #4
  5. Umesh

    Guru Jois Guest

    On Jun 4, 11:33 pm, 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?
    >

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

    On Unix box, use 'time' <command> to 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
     
    Guru Jois, Jun 5, 2007
    #5
  6. Umesh

    osmium Guest

    "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.
     
    osmium, Jun 5, 2007
    #6
  7. Umesh

    Chris Hills Guest

    In article <>,
    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?
    >
    >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 /\/\/\/\/
    /\/\/ www.phaedsys.org \/\/\
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
     
    Chris Hills, Jun 5, 2007
    #7
  8. Guru Jois said:

    > On Jun 4, 11:33 pm, 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?
    >>

    > 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.
     
    Richard Heathfield, Jun 5, 2007
    #8
  9. Umesh

    Richard Guest

    Richard Heathfield <> writes:

    > Guru Jois said:
    >
    >> On Jun 4, 11:33 pm, 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?
    >>>

    >> 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?
     
    Richard, Jun 5, 2007
    #9
  10. 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.
     
    Richard Heathfield, Jun 5, 2007
    #10
  11. Richard said:

    > Richard Heathfield <> writes:
    >
    >> Guru Jois said:
    >>
    >>> On Jun 4, 11:33 pm, 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?
    >>>>
    >>> 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.
     
    Richard Heathfield, Jun 5, 2007
    #11
  12. Umesh

    Lew Pitcher Guest

    On Jun 5, 2:33 am, 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?


    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.
     
    Lew Pitcher, Jun 5, 2007
    #12
  13. Umesh

    Chris Hills Guest

    In article <>, osmium
    <> writes
    >"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 /\/\/\/\/
    /\/\/ www.phaedsys.org \/\/\
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
     
    Chris Hills, Jun 5, 2007
    #13
  14. Umesh

    Chris Hills Guest

    In article <46655e6f$0$56919$>,
    Thad Smith <> writes
    >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 /\/\/\/\/
    /\/\/ www.phaedsys.org \/\/\
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
     
    Chris Hills, Jun 5, 2007
    #14
  15. Umesh

    Chris Dollin Guest

    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
     
    Chris Dollin, Jun 5, 2007
    #15
  16. Umesh

    Thad Smith Guest

    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
     
    Thad Smith, Jun 5, 2007
    #16
  17. Umesh

    Richard Guest

    Richard Heathfield <> writes:

    > Richard said:
    >
    >> Richard Heathfield <> writes:
    >>
    >>> Guru Jois said:
    >>>
    >>>> On Jun 4, 11:33 pm, 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?
    >>>>>
    >>>> 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.
     
    Richard, Jun 5, 2007
    #17
  18. Umesh

    Chris Hills Guest

    In article <f43p4l$8jp$>, Chris Dollin
    <> writes
    >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 /\/\/\/\/
    /\/\/ www.phaedsys.org \/\/\
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
     
    Chris Hills, Jun 5, 2007
    #18
  19. Umesh

    Chris Dollin Guest

    Chris Hills wrote:

    > In article <f43p4l$8jp$>, Chris Dollin
    > <> writes
    >>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
     
    Chris Dollin, Jun 5, 2007
    #19
  20. Umesh

    Chris Hills Guest

    In article <f43ruu$a9v$>, Chris Dollin
    <> writes
    >Chris Hills wrote:
    >
    >> In article <f43p4l$8jp$>, Chris Dollin
    >> <> writes
    >>>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 /\/\/\/\/
    /\/\/ www.phaedsys.org \/\/\
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
     
    Chris Hills, Jun 5, 2007
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. flamesrock
    Replies:
    8
    Views:
    469
    Hendrik van Rooyen
    Nov 24, 2006
  2. Replies:
    9
    Views:
    389
    Michael DOUBEZ
    Feb 5, 2009
  3. Kelvin
    Replies:
    1
    Views:
    205
    Aaron Bertrand [SQL Server MVP]
    Jul 13, 2005
  4. Jayesh Kamdar
    Replies:
    2
    Views:
    158
    Gunnar Hjalmarsson
    May 25, 2005
  5. Washington Ratso
    Replies:
    1
    Views:
    62
    Chris “Kwpolska†Warrick
    Apr 3, 2014
Loading...

Share This Page