admin管理员组

文章数量:1414628

Just a noob question.

I run the following code on visual studio release mode. And is finishing almost immidiatelly meaning running through long long largeNumber = 9223372036854775807 increasments at so little time.

So how that is possible?

#include <iostream>
using namespace std;

int main()
{
    std::cout << "Hello World!\n";
    int ok;
    cin >> ok;
    cout << "starting\n";
    long long i=1;
    while (i > 0) {
        ++i;

    }
    --i;
    cout <<"last:" << i << "\n";

}

i was expecting that will take some seconds at least. I though that a processor lets say 3.40 GHz simply mean that can make up to 3.4 billion actions on a second.!

PS.in java seems to go as slow as i was expecting.

public class NewClass1 {
    public static void main(String[] args) {
        long ts=System.currentTimeMillis();
        long i=1;
        while(i>0){
            ++i;
        }
        long te =System.currentTimeMillis();
        --i;
        System.out.println("last: "+i +" in millis:"+(te-ts));
    }
}```


本文标签: performancewhy c run a while(long longgt0) in just under a second on CPU 340GHzStack Overflow