Thread: execution time

  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,210
    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

  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, 07:45 AM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM