execution time

This is a discussion on execution time within the C++ Programming forums, part of the General Programming Boards category; Hi, I am running a simulation and want to print out the execution time at each iteration. Is there a ...

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    65

    execution time

    Hi,

    I am running a simulation and want to print out the execution time at each iteration. Is there a C++ command for this?

    Shuo

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Not to be pedantic, but C++ does not have "commands" per se.

    Anyway, built into C++, no, unless you count the clock() function or even the time_t functions. The latter is probably your best bet, but it depends upon how precise and accurate you need to be.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    If you're looking for anything which is consistently below 1 second, then you need to be specific about which OS/Compiler you're using.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Salem View Post
    If you're looking for anything which is consistently below 1 second, then you need to be specific about which OS/Compiler you're using.
    clock() is as close as you can usually get for a portable, "high precision" timer. It is not very precise, but it will give you a decent timing. It usually manages to be precise to about 0.1 second, but shorter times than that requires less portable solutions, usually.

    http://www.hmug.org/man/3/clock.php

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mac OS X Users/C programmers?
    By petermichaux in forum C Programming
    Replies: 16
    Last Post: 04-18-2011, 06:36 AM
  2. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  3. How to get current time
    By tsubasa in forum C Programming
    Replies: 3
    Last Post: 05-01-2009, 02:03 AM
  4. How to get program execution time
    By pobri19 in forum C++ Programming
    Replies: 8
    Last Post: 01-20-2009, 06:45 AM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 09:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21