-
Notifications
You must be signed in to change notification settings - Fork 4
/
calc.cpp
49 lines (38 loc) · 870 Bytes
/
calc.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
48
49
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <time.h>
#include <math.h>
#define MAG 1000000
using namespace std;
void time_start();
void time_end(char*);
double START,END;
int main(){
int a = 554464;
float b = 0.76546;
time_start();
int a_2 = 0;
float a_2_p = 0.0;
float b_2 = 0.0;
float b_b_p = 0.0;
for (int i=1;i<=MAG;i++) a_2 += a * a;
time_end("a*a, ");
time_start();
for (int i=1;i<=MAG;i++) a_2_p += pow(a,2);
time_end("pow(a,2), ");
time_start();
for (int i=1;i<=MAG;i++) b_2 += b * b;
time_end("b*b, ");
time_start();
for (int i=1;i<=MAG;i++) b_b_p += pow(b,2);
time_end("pow(b,2), ");
return 0;
}
void time_start(){
START = clock();
}
void time_end(char *str){
END = clock();
cout << endl << str << "進行運算所花費的時間:" << (END - START) / CLOCKS_PER_SEC << " S" << endl;
}