分别使用 C++、java、rust 作空循环大约 20 亿次,统计其运行时间。程序运行时间统计方法见代码。
C++
#include <iostream>
using namespace std;
int main() {
auto begin = clock(); //us
// //for-loop
// for(int i=0;i<INT_MAX;i++)
// {
//
// } //1.5s 1.3s 1.3s 1.3s 1.3s
// //about 1.3s
//while-loop
int i=0;
while(i++<INT_MAX);
//1.4s 1.3s 1.3s 1.3s 1.3s 1.3