-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
47 lines (35 loc) · 1.42 KB
/
main.cpp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <time.h>
#include <stdio.h>
#include <iostream>
#include <chrono>
using namespace std;
int main (){
// input prompt for .cpp file name
char filename[100];
cout << "Name of .cpp file to be compiled: ";
cin.getline(filename, 100);
// assemble command to compile
// program using system()
string str = "g++ ";
str = str + " -o a.out " + filename;
const char *command = str.c_str();
// output system command
cout << "Using system command: " << command << endl;
// output status update
cout << "Compiling and running file " << endl;
auto start = chrono::steady_clock::now(); // start timer
system(command); // compile
system("./a.out"); // run
auto end = chrono::steady_clock::now(); // end timer
cout << "Execution time in nanoseconds: "
<< chrono::duration_cast<chrono::nanoseconds>(end - start).count() << " ns" << endl;
cout << "Execution time in microseconds: "
<< chrono::duration_cast<chrono::microseconds>(end - start).count() << " µs" << endl;
cout << "Execution time in milliseconds: "
<< chrono::duration_cast<chrono::milliseconds>(end - start).count() << " ms" << endl;
cout << "Execution time in seconds: "
<< chrono::duration_cast<chrono::seconds>(end - start).count() << " sec";
// pause to exit
int ch = getchar();
return 0;
}