📄 comparison.cpp
字号:
#include "Dice.h"
#include <iostream>
using std::wcout;
using std::endl;
#define for if(0);else for
int main()
{
Dice dice(10);
unsigned long diceTotal = 0;
time_t beg, end;
beg = time(NULL);
diceTotal = dice.multi(500000000);
end = time(NULL);
wcout << L"Using member function multi(), total = " << diceTotal << endl;
wcout << L" in " << (end - beg) << L" seconds." << endl << endl;
diceTotal = 0;
beg = time(NULL);
for(long i=0; i<500000000; ++i)
{
diceTotal += dice.roll();
}
end = time(NULL);
wcout << L"Using member function roll(), total = " << diceTotal << endl;
wcout << L" in " << (end - beg) << L" seconds." << endl << endl;
diceTotal = 0;
beg = time(NULL);
for(long i=0; i<500000000; ++i)
{
diceTotal += Dice(10);
}
end = time(NULL);
wcout << L"Repeatedly constructing Dice objects, total = " << diceTotal << endl;
wcout << L" in " << (end - beg) << L" seconds." << endl << endl;
diceTotal = 0;
beg = time(NULL);
for(long i=0; i<500000000; ++i)
{
diceTotal += static_cast<int>(rand()%(10)) + 1;
}
end = time(NULL);
wcout << L"Directly calling rand(), total = " << diceTotal << endl;
wcout << L" in " << (end - beg) << L" seconds." << endl << endl;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -