-
Notifications
You must be signed in to change notification settings - Fork 0
/
clock tick test.c
72 lines (56 loc) · 1.6 KB
/
clock tick test.c
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdio.h>
#include <time.h>
void real_time(int,int,int,double *p);
int main(void){
double time_start,time_end;
const int FREQUENCY = 1e6;
double time_real;
time_start = clock();
for (int i = 0; i < FREQUENCY; i++)
{
// 放测试用函数*****************
int input_1 = 2;
int input_2 = 50;
int num_sum = 0;
int x,y,z;
int num_state = 1;
for (input_1 = input_1; input_1 <= input_2; input_1++)
{
num_state = 1;
if (input_1 == 1)
{
input_1 = 2;
}else if (input_1 == 2)
{
y++;
num_sum += input_1;
}
for ( x = 2; x < input_1; x++)
{
if (input_1 % x == 0)
{
num_state = 0;
break;
}
}
if (num_state == 1)
{
y++;
num_sum += input_1;
}
}
// printf("%d %d\n",y,num_sum);
// *******************************************
}
time_end = clock();
real_time( time_start, time_end, FREQUENCY, &time_real);
printf("realtime = %lf",time_real);
return 0;
}
void real_time(int time_start ,int time_end,int FREQUENCY,double *p){
*p = ((double)time_end-time_start)/CLK_TCK/FREQUENCY;
printf("time_start = %d\n",time_start);
printf("time_end = %d\n",time_end);
printf("CLK_TCK = %d\n",CLK_TCK);
printf("*p = %x\n",p);
}