⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 comparison.cpp

📁 为大家搜集免费的计算机学习、编程资料和优秀的网络资源。多多支持
💻 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 + -