Runtime??

Shouldn't a for loop which loops 10 time have a greater runtime than a for loop with 5 loops?
If so, how come am I getting the same result in both cases??
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int main(int argc, const char * argv[])
{
 chrono::time_point<chrono::system_clock> start,end;
    chrono::duration<float,micro> elapsed_seconds;
    ofstream myfile;
    int n = 0;
    
    cout << "computes f(n), what should n be?" << endl;
    cin >> n;
    myfile.open("stats.txt");
    
    for (int i = 0; i<=n; i++) {
        myfile << i ;
        start = chrono::system_clock::now();
        fibonacci(i); // not recursive method
        end  =  chrono::system_clock::now();
        elapsed_seconds = end-start;
        //cout << "finished computation - normal f("<<i<<") " << "time: "   << elapsed_seconds.count() << "ms" << endl;
        myfile << ";" << elapsed_seconds.count() << endl;
}
return 0
}
Maybe fibonacci() ends so quickly that chrono::system_clock::now() doesn't have enough precision. Maybe the compiler noticed that fibonacci() doesn't have any side effects and its return value is discarded, so it decided to simply not call it.
I've tested it by printing the result, and so no of the values gets discarded.
Precision might swell be the reason, until i tried a ratio of 1,100000000, and it still gave me results 1*10000000 and 0.
Topic archived. No new replies allowed.