How to find compilation/execution time in C?

vignesh1988i
@vignesh1988i-uWq8hQ โ€ข Oct 27, 2024

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 !!!!!!!!๐Ÿ˜”๐Ÿ˜”๐Ÿ˜”๐Ÿ˜”๐Ÿ˜”๐Ÿ˜”

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • vignesh1988i

    @vignesh1988i-uWq8hQ • Jan 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 ๐Ÿ˜€

  • Manish Goyal

    @manish-r2Hoep • Jan 9, 2010

    Sorry vignesh..your question confuse me..
    Is there any difference between processor time and run time?
    sorry if my question is silly?

  • vignesh1988i

    @vignesh1988i-uWq8hQ • Jan 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

  • ms_cs

    @ms-cs-Ab8svl • Jan 9, 2010

    vignesh1988iok 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..

  • vignesh1988i

    @vignesh1988i-uWq8hQ • Jan 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

  • ms_cs

    @ms-cs-Ab8svl • Jan 9, 2010

    What is the problem you faced with that? post what you tried, here

  • vignesh1988i

    @vignesh1988i-uWq8hQ • Jan 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???????

  • Manish Goyal

    @manish-r2Hoep • Jan 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?

  • ms_cs

    @ms-cs-Ab8svl • Jan 9, 2010

    see this link,

    #-Link-Snipped-#

  • vignesh1988i

    @vignesh1988i-uWq8hQ • Jan 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 ๐Ÿ˜€ ๐Ÿ˜€

  • Manish Goyal

    @manish-r2Hoep • Jan 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

  • vignesh1988i

    @vignesh1988i-uWq8hQ • Jan 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 ๐Ÿ˜”

  • Manish Goyal

    @manish-r2Hoep • Mar 31, 2023

    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