CrazyEngineers
  • How to find compilation/execution time in C?

    Updated: Oct 27, 2024
    Views: 1.3K
    how to find the compilation time or execution time in C??????? wat function we must use to find the operation time in milli seconds??????????? it's very urgent !!!!!!!!😔😔😔😔😔😔
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Manish Goyal

    MemberJan 8, 2010

    Re: A urgent help needed!!!!!! plzzzzz

    Hello vignnesh there is no need of any function to know the run time
    just do what i say?
    In c++ program window
    just write any program and execute it
    after getting output click on option 'compile' in menu bar...then click 'information'
    a window will open in which run time of program will be mentioned
    ''Don't confuse with c++ program window by which i mean blue screen''there you can execute both c++ and c program
    Are you sure? This action cannot be undone.
    Cancel
  • vignesh1988i

    MemberJan 9, 2010

    YA THANKS allot for ur fast reply 😀 😀 , but actually wat i need is the processor time .... but here its taking the whole run time (ie) as soon as the exe window opens to till it returns to the program screen or to editor.......
    BUT I NEED THE PROCESSOR TIME , so can u help for that 😀
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberJan 9, 2010

    Sorry vignesh..your question confuse me..
    Is there any difference between processor time and run time?
    sorry if my question is silly?
    Are you sure? This action cannot be undone.
    Cancel
  • vignesh1988i

    MemberJan 9, 2010

    ok ok ok 😀 here i ll explain u with a neat example .......

    let us take the code :

    main()
    {
    int n;
    clrscr();
    printf("enter the number :");
    scanf("%d",&n); Input session

    if(n>0) line 6
    printf("%d is +ve",n);
    else if(n<0)
    printf("%d is -ve",n);
    else
    printf(" 0 value "); line 11

    getch();
    }

    here i need to calculate the execution time from line 6 to line 11 alone in milliseconds 😀 , because that one is the processing time where i do manipuations or operations na , 😀

    But in the option "COMPILE" , the "INFORMATION" option is giving the total time in milliseconds , which is including the input time to till coming back to the editor mode 😀 😀 that's why iam asking 😀 sorry 😔

    thank u
    Are you sure? This action cannot be undone.
    Cancel
  • ms_cs

    MemberJan 9, 2010

    vignesh1988i
    ok ok ok 😀 here i ll explain u with a neat example .......

    let us take the code :

    main()
    {
    int n;
    clrscr();
    printf("enter the number :");
    scanf("%d",&n); Input session

    if(n>0) line 6
    printf("%d is +ve",n);
    else if(n<0)
    printf("%d is -ve",n);
    else
    printf(" 0 value "); line 11

    getch();
    }

    here i need to calculate the execution time from line 6 to line 11 alone in milliseconds 😀 , because that one is the processing time where i do manipuations or operations na , 😀

    But in the option "COMPILE" , the "INFORMATION" option is giving the total time in milliseconds , which is including the input time to till coming back to the editor mode 😀 😀 that's why iam asking 😀 sorry 😔

    thank u

    Hey Dude ,

    Sure you can calculate,

    You can do this with the help of time.h header file,
    if still you have problem let me know..
    Are you sure? This action cannot be undone.
    Cancel
  • vignesh1988i

    MemberJan 9, 2010

    i have tried that 😀 , but pl. let me know about ur view , which function we must use to get the process time in milliseconds 😀 , pl. reply me immediately 😀

    thank u
    Are you sure? This action cannot be undone.
    Cancel
  • ms_cs

    MemberJan 9, 2010

    What is the problem you faced with that? post what you tried, here
    Are you sure? This action cannot be undone.
    Cancel
  • vignesh1988i

    MemberJan 9, 2010

    In time.h , there is a structure called time_t as u know it......
    i calculated the start time by giving :

    main()
    {
    int n;
    time_t t1 , t2;
    clrscr();
    scanf("%d",&n);
    time(&t1);
    //starting of the process
    if(n%2==0)
    printf("even")
    else
    printf("odd");
    // end of the process
    time(&t2);

    printf("\n%d",difftime(t2,t1));
    getch();
    }

    this only i gave , but am getting the answer in SEC. but i need the correct milliseconds time for the above code........ (ie) only the process time..... 😀 😀 can u understand???????
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberJan 9, 2010

    I don't know about this..but why don't you create a function that will convert seconds into milliseconds...may be you will get what you want?
    Are you sure? This action cannot be undone.
    Cancel
  • ms_cs

    MemberJan 9, 2010

    see this link,

    #-Link-Snipped-#
    Are you sure? This action cannot be undone.
    Cancel
  • vignesh1988i

    MemberJan 9, 2010

    actually i know the conversion,,, the problem is that i cant able to see the small difference when i get the o/p in seconds.........

    for example :
    for checking a given number is even or odd : we will check with the if - else construct.....

    if( i%2==0) // this is the process for me.... i need to find out this time in milliseconds

    if i check for a number whether it is +ve or -ve ,

    if( a>0) // process

    else if(a<0) // process


    this time in milli seconds i need to find 😀 😀


    hope u can understand my question now fully 😀 😀


    can u give a solution for me 😀 😀
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberJan 9, 2010

    Try this it may help you
    #include<iostream.h>
    #include<conio.h>
    #include<time.h>
    
    void main()
    {
    int n;
    time_t t1 , t2;
    clrscr();
    cin>>n;
    time(&t1);
    //starting of the process
    if(n%2==0)
    cout<<"even";
    else
    cout<<"odd";
    // end of the process
    double d; 
    d=difftime(t2,t1);
    cout<<d<<endl;
    getch();
    }
    I have made small changes
    Are you sure? This action cannot be undone.
    Cancel
  • vignesh1988i

    MemberJan 9, 2010

    HMMMM 😀 😀 i have tried that , i too converted into milliseconds too... but i can't able to see small changes or difference in time , since i need a precised value in the difference in timings only i asked u for a solution 😀 😀 , sorry for troubling 😔
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register