Finding Program Running Time

This is a discussion on Finding Program Running Time within the C Programming forums, part of the General Programming Boards category; Hi, I'm a new C student, and I need to find out how long my program takes to run. i'm ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    3

    Finding Program Running Time

    Hi, I'm a new C student, and I need to find out how long my program takes to run. i'm using the following code, but I get a ton of C2143 errors when I use this. When I don't use anything in <time.h>, my program compiles, and works perfectly. I'm using MS Visual C++ (even though I'm trying to program in C).

    Is there a problem with my code?
    Code:
    #include <time.h>
    int main ()
    { 
      clock_t start, end;
      double runTime;
      start = clock();
      /* my actual program */
      end = clock();
      runTime = ((end – start) / (double) CLOCKS_PER_SEC );
      printf (“Run time is %g seconds”, runTime);
      getch();
      return 0;
    }

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,274
    Quote Originally Posted by pf732k3 View Post
    Hi, I'm a new C student, and I need to find out how long my program takes to run. i'm using the following code, but I get a ton of C2143 errors when I use this. When I don't use anything in <time.h>, my program compiles, and works perfectly. I'm using MS Visual C++ (even though I'm trying to program in C).
    Please give the exact text of the C2143 error.

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    3
    error C2143: syntax error : missing ';' before 'type'

    After the clock function, I'm initializing some int variables and some char arrays.

  4. #4
    Registered User
    Join Date
    Jan 2008
    Posts
    287
    I'm getting errors compiling your code because it has strange characters in it.

    Code:
      runTime = ((end – start) / (double) CLOCKS_PER_SEC );
      printf (“Run time is %g seconds”, runTime);
    On those two lines, the '-' character in the expression (end - start) isn't a normal hyphen character. Also, the quotes you used in your string literal aren't normal double quotes either.

  5. #5
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Code:
    #include <time.h>
    #include <stdio.h>
    
    int main ()
    { 
      clock_t start, end;
      double runTime;
      start = clock();
      /* my actual program */
      end = clock();
      runTime = (end - start) / (double) CLOCKS_PER_SEC ;
      printf ("Run time is &#37;g seconds\n", runTime);
      getchar();
      return 0;
    }
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  6. #6
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,274
    Quote Originally Posted by arpsmack View Post
    I'm getting errors compiling your code because it has strange characters in it.
    What the heck was the OP using for an editor? Word?

  7. #7
    Registered User
    Join Date
    Jan 2008
    Posts
    287
    Haha, you know I almost added that as an edit.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using getchar to keep program running
    By shadow1515 in forum C Programming
    Replies: 8
    Last Post: 05-25-2008, 03:33 AM
  2. Multi - File Program not finding files
    By johnh444 in forum C++ Programming
    Replies: 2
    Last Post: 07-03-2004, 02:48 AM
  3. The space time continueimnms mm... (rant)
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 32
    Last Post: 06-27-2004, 02:21 PM
  4. Geophysics student needs help in running a C++ program
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 01-29-2002, 02:15 AM
  5. Running program on background?
    By Couhilin in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2001, 07:50 AM

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