unsure

This is a discussion on unsure within the C Programming forums, part of the General Programming Boards category; I am trying to time how long it takes for a program to execute the program below is working but ...

  1. #1
    Unregistered
    Guest

    unsure

    I am trying to time how long it takes for a program to execute

    the program below is working but I am not sure whether it is doing what it's suppsose to do.

    I never used system() so I am not sure whether I used it correctly in here. The program that I am timing is called flotlim.exe

    Also do I have to put the codes for flotlim in this programs or just writting system("flotlim.exe") is enough?

    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <time.h>

    int main(void)
    int k,n;
    double elapsed;
    clock_t start_time, end_time;

    start_time=clock();
    system("flotlim.exe");

    for (n=0;n<5000; n++) for(k=0;k<5000;k++);
    end_time=clock();

    elapsed=difftime(end_time, start_time)/(double)CLOCKS_PER_SEC;

    printf("%ld %ld\n", start_time, end_time);
    printf("%f %f\n", start_time/CLOCKS_PER_SEC,end_time/CLOCKS_PER_SEC);
    printf("%3.1lf%s\n", elapsed, "seconds");

    return 0;
    }

  2. #2
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    Here is a small example using clock().
    Code:
    include <time.h>
    #include <stdio.h>
    #include <windows.h> // For the Sleep function
    int main(void)
    {
    	double timedif;
    	double time1 = (double)clock();
    	time1 = time1/(double)CLOCKS_PER_SEC;
    	Sleep(1500);
    	timedif = (((double)clock()) / (double)CLOCKS_PER_SEC) - time1;
    	printf("The elapsed time is %f seconds\n",timedif);
    }
    - Sean
    Last edited by sean345; 08-12-2002 at 04:34 PM.
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  3. #3
    Visionary Philosopher Sayeh's Avatar
    Join Date
    Aug 2002
    Posts
    212
    I am trying to time how long it takes for a program to execute
    Better compilers have things called 'Profilers' which can give you an idea where time is spent in your program's different routines.

    the program below is working but I am not sure whether it is doing what it's suppsose to do
    The only way to really be sure the app is doing what you want, is to step through the program with a debugger. Then you see everything.
    It is not the spoon that bends, it is you who bends around the spoon.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New to Forms/MFC. Unsure where to place the code.
    By Swerve in forum Windows Programming
    Replies: 1
    Last Post: 02-02-2009, 12:15 AM
  2. Unsure on how to approach this concurrency problem
    By osiris^ in forum C# Programming
    Replies: 3
    Last Post: 04-29-2008, 11:47 PM
  3. unsure about auto/smart pointers
    By l2u in forum C++ Programming
    Replies: 16
    Last Post: 07-13-2007, 12:55 PM
  4. Unsure of how to setup this function
    By Khem101 in forum C Programming
    Replies: 4
    Last Post: 10-03-2006, 07:32 AM
  5. Unsure of how to properly use extern "C"
    By INFERNO2K in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2005, 10:54 AM

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