Thread: Finding out how long it takes for a program to run.

  1. #1
    Unregistered
    Guest

    Question Finding out how long it takes for a program to run.

    This is a basic outline of my program here:

    #include <iostream.h>
    #include <sys/types.h>
    #include <stdlib.h>
    #include <time.h>
    #include <math.h>

    main () {
    int i; time_t t1, t2;
    .... all variables, etc. go here
    (void) time (&t1);
    ... entire code goes here
    (void) time (&t2);
    cout<<"CPU time required to execute the program "<<(int) t2-t1<<endl;
    }

    The problem I am having is that I get a value of "0" for time required to execute the program. I am working in C++ and don't know how this problem can be fixed... I've tried to use different types for the time statement, float, double, but nothing seems to work. Does anyone else have suggestions or a better way to execute this?? thanks in advance

  2. #2
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    you could use ftime and the timeb structure, that would give you a greater precision too [milliseconds] as well as other useful data, if you use it...
    hasafraggin shizigishin oppashigger...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program running long
    By smarta_982002 in forum Windows Programming
    Replies: 3
    Last Post: 03-27-2008, 05:24 AM
  2. Finding Program Running Time
    By pf732k3 in forum C Programming
    Replies: 6
    Last Post: 03-18-2008, 01:56 PM
  3. Replies: 2
    Last Post: 12-22-2006, 08:45 PM
  4. popen takes too long?
    By Largo in forum C Programming
    Replies: 2
    Last Post: 11-20-2006, 06:46 AM
  5. can someone check this out and let me know ?
    By javaz in forum C Programming
    Replies: 5
    Last Post: 01-21-2002, 02:13 PM