Application Compute Time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dolcetheking
    New Member
    • Apr 2007
    • 5

    Application Compute Time

    i got the Fibonacci Numbers algorithm :

    #include <iostream>
    using namespace std;

    int fib (int n)
    {
    if (n<3)
    return (1);
    else
    return (fib(n-2)+fib(n-1));
    }
    int main()
    {
    cout<<"Fibbonac iu Numbers: 1, 1, 2, 3, 5, 8, 13, 21,...\n"<<endl ;
    int n, Result;
    cout<<"n = "; cin>>n;
    Result=fib(n);
    cout<<"\n\tfib ( "<<n<<" ) = "<<Result;
    cin.get(); cin.get();
    return 0;
    }

    I need to measure the app.compute time about number 1 , 5 , 10 , 20 , 30 , 40 and 50
  • milirica
    New Member
    • Apr 2007
    • 2

    #2
    mate me sahat

    Comment

    • nmadct
      Recognized Expert New Member
      • Jan 2007
      • 83

      #3
      The standard function to get the current time is called, unsurprisingly, "time".


      Unfortunately, the time function counts in seconds, and for your purposes it looks like that's not enough precision. If your system has it, you can use gettimeofday, which returns the time in milliseconds.


      I don't think Windows has gettimeofday, however. If you're using Windows you'll need a different solution. One function you could use is QueryPerformanc eCounter(), which gives the time in microseconds. I've never tried it but here are some web pages you could check out:

      Comment

      Working...