Question

I can´t count the time of cpu processing in cygwin?Why is that? Do I need a special command.Counting clicks in cpu is done by clock function after including time.h!

Still, after i get it done in visual studio i just can´t run on cygwin? Why is that!

Here is the code.

#include <iostream>
#include <time.h>
using namespace std;
int main()
{

    clock_t t1,t2;

    int x=0;
    int num;
    cout << "0 to get out of program, else, number of iterations" << endl;
    cin>>num;

    if(num==0)
    system(0);
    t1=clock();
    while (x!=num)
        {
        cout << "Number "<<x<<" e"<< endl;
        if(x%2==0)
            cout << "Even" << endl;
        else
            cout << "Odd" << endl;
        x=x+1;
        }


    t2=clock();
    float diff ((float)t2-(float)t1);
    cout<<diff<<endl;
    float seconds = diff / CLOCKS_PER_SEC;
    cout<<seconds<<endl;
    system ("pause");
    return 0;
}

Sorry for the bad english.

Was it helpful?

Solution

Looks like the clock() function is defined differently for Windows and POSIX (and hence Cygwin). MSDN says that the Windows clock() returns "the elapsed wall-clock time since the start of the process", whereas the POSIX version returns "the implementation's best approximation to the processor time used by the process". In your example, the process will be spending almost its entire time waiting for output to the terminal to complete, which doesn't count towards the processing time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top