Skip to content

Instantly share code, notes, and snippets.

@sarhej
Created March 17, 2013 13:22
Show Gist options
  • Select an option

  • Save sarhej/5181483 to your computer and use it in GitHub Desktop.

Select an option

Save sarhej/5181483 to your computer and use it in GitHub Desktop.

Revisions

  1. sarhej created this gist Mar 17, 2013.
    60 changes: 60 additions & 0 deletions Fibo2.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    #include <iostream>
    #include <fstream>
    #include <math.h>
    #include <sys/time.h>
    #include <stdint.h>

    using namespace std;
    const double SQRT5 = 2.2360679774997896964091736687313;
    const double _x_SQRT5 = 0.44721359549995793928183473374626;
    const double SQRT2 = 1.6180339887498948482045868343656;
    const double _x_LOGSQRT = 0.01615166883467606905979721930442;


    double GetTickCount()
    {
    struct timeval tv;
    if(gettimeofday(&tv, NULL) != 0)
    return 0;

    return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
    }


    int main(int argc, char* argv[])
    {
    uint32_t counter = 10000000;

    uint32_t n = 4000000;

    uint32_t f1 = 0;
    uint32_t f2 = 1;
    uint32_t f3;

    uint32_t _oldTicks = GetTickCount();

    for ( uint32_t i = 1; i < counter; i++)
    {
    f1 = 0;
    f2 = 1;
    while (f1<n)
    {
    f3 = f1+f2;
    f1 = f2+f3;
    f2 = f3+f1;
    }
    (uint32_t)((f3-1)/2);
    }
    uint32_t _newTicks = GetTickCount();

    cout << "Time passed by sum: " << (_newTicks - _oldTicks) << endl;


    uint32_t _oldTicks2 = GetTickCount();
    for (double i = 1; i < counter; i++)
    (uint32_t)((floor(pow(SQRT2, floor(log( n * SQRT5 ) * _x_LOGSQRT) * 3 + 2)*_x_SQRT5 + 0.5) - 1) / 2);
    uint32_t _newTicks2 = GetTickCount();
    cout << "Time passed by logarithm: " << (_newTicks2 - _oldTicks2) << endl;

    return 0;
    }