Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 06 / Macros / macrosExample.cpp
blob: fe08c2c4dd8cec5b7aaff2857e3f40f4a1289e58 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <string.h>
#include <ctime>

//example for a macro
#define MAX(a,b) (a>b ? a : b)

using namespace std;


int max(int a, int b)
{
	return a > b ? a : b;
}
int main()
{
	clock_t begin = clock();

	for (int i = 0; i < 10000000; i++)
		max(4, 10);

	clock_t end = clock();
	cout << "10000000 calls of max function: " << double(end - begin)<<endl;

	begin = clock();
	for (int i = 0; i < 10000000; i++)
		MAX(4, 10);
	end = clock();
	cout << "10000000 times with macro: " << double(end - begin)<<endl;
	return 0;
}