-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha.cpp~
50 lines (46 loc) · 1005 Bytes
/
a.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
50
#include<stdio.h>
#include<google/profiler.h>
#include<stdlib.h>
#include<unistd.h>
void consumeSomeCPUTime1(int input){
int i = 0;
input++;
while(i++ < 10000){
i--; i++; i--; i++;
}
};
void consumeSomeCPUTime2(int input){
input++;
consumeSomeCPUTime1(input);
int i = 0;
while(i++ < 10000){
i--; i++; i--; i++;
}
};
int stupidComputing(int a, int b){
int i = 0;
while( i++ < 10000){
consumeSomeCPUTime1(i);
}
int j = 0;
while(j++ < 5000){
consumeSomeCPUTime2(j);
}
return a+b;
};
int smartComputing(int a, int b){
return a+b;
};
int main(){
int i = 0;
printf("reached the start point of performance bottle neck\n");
sleep(5);
ProfilerStart("CPUProfile");
while( i++ < 10){
printf("Stupid computing return : %d\n",stupidComputing(i, i+1));
printf("Smart computing return %d\n",smartComputing(i+1, i+2));
}
printf("should teminate profiling now.\n");
sleep(5);
ProfilerStop();
}