Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
1 files changed, 31 insertions, 0 deletions
-rw-r--r--Sem. 06/Macros/macrosExample.cpp31
diff --git a/Sem. 06/Macros/macrosExample.cpp b/Sem. 06/Macros/macrosExample.cpp
new file mode 100644
index 0000000..fe08c2c
--- /dev/null
+++ b/Sem. 06/Macros/macrosExample.cpp
@@ -0,0 +1,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;
+}