-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp_branch_efficiency.cpp
More file actions
54 lines (40 loc) · 1012 Bytes
/
cpp_branch_efficiency.cpp
File metadata and controls
54 lines (40 loc) · 1012 Bytes
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
50
51
52
53
54
#include <iostream>
#include <time.h>
using namespace std;
int main()
{
clock_t start, end;
int N = 32;
int var[32] = {0};
int var1[32] = {1};
int var_test = 0;
for(int i = 0; i < N; i++)
var1[i] = var[i] = i;
start = clock();
for (int i = 0; i < N*100000; i++)
{
int j = i % N;
var_test = var[j];
if(j == 0)
var[j] = var[j] + 1;
else
var[j] = var [j] + 2;
var[j] = var[j] * 3;
var[j] = var_test;
}
end = clock();
cout<<"Run time: "<<(double)(end - start) / CLOCKS_PER_SEC<<"S"<<endl;
start = clock();
for (int i = 0; i < N*100000; i++)
{
int j = i % N;
var_test = var1[j];
var1[j] = (var1[j] + 1 + (var1[j] > 0)) * 3;
var1[j] = var_test;
}
end = clock();
cout<<"Run time: "<<(double)(end - start) / CLOCKS_PER_SEC<<"S"<<endl;
for(int i = 0; i < N; i++)
cout << var[i] - var1[i] << endl;
return 0;
}