-
Notifications
You must be signed in to change notification settings - Fork 162
/
benchmark.c
181 lines (176 loc) · 4.65 KB
/
benchmark.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
extern int seconds, thirds;
void rBenchmark(daveConnection * dc, int bmArea) {
int i,res,maxReadLen,areaNumber;
double usec;
PDU p;
#ifdef UNIX_STYLE
struct timeval t1, t2;
#endif
#ifdef BCCWIN
clock_t t1, t2;
#endif
seconds=0;thirds=0;
maxReadLen=dc->maxPDUlength-46;
areaNumber=0;
if(bmArea==daveDB) areaNumber=1;
printf("Now going to do read benchmark with minimum block length of 1.\n");
wait();
#ifdef UNIX_STYLE
gettimeofday(&t1, NULL);
#endif
#ifdef BCCWIN
t1=clock();
#endif
for (i=1;i<101;i++) {
daveReadBytes(dc, bmArea, areaNumber,0, 1, NULL);
if (i%10==0) {
printf("...%d",i);
fflush(stdout);
}
}
#ifdef UNIX_STYLE
gettimeofday(&t2, NULL);
usec = 1e6 * (t2.tv_sec - t1.tv_sec) + t2.tv_usec - t1.tv_usec;
usec/=1e6;
#endif
#ifdef BCCWIN
t2=clock();
usec = 0.001*(t2 - t1);
#endif
printf(" 100 reads took %g secs. \n",usec);
printf(" retries: 2nd %d 3rd %d\n",seconds, thirds);
seconds=0;thirds=0;
printf("Now going to do read benchmark with shurely supported block length %d.\n",maxReadLen);
// daveSetDebug(daveDebugAll);
wait();
#ifdef UNIX_STYLE
gettimeofday(&t1, NULL);
#endif
#ifdef BCCWIN
t1=clock();
#endif
for (i=1;i<101;i++) {
daveReadBytes(dc, bmArea, areaNumber, 0, maxReadLen, NULL);
if (i%10==0) {
printf("...%d",i);
fflush(stdout);
}
}
#ifdef UNIX_STYLE
gettimeofday(&t2, NULL);
usec = 1e6 * (t2.tv_sec - t1.tv_sec) + t2.tv_usec - t1.tv_usec;
usec/=1e6;
#endif
#ifdef BCCWIN
t2=clock();
usec = 0.001*(t2 - t1);
#endif
printf(" 100 reads took %g secs. \n",usec);
printf(" retries: 2nd %d 3rd %d\n",seconds, thirds);
wait();
seconds=0;thirds=0;
printf("Now going to do read benchmark with 5 variables in a single request.\n");
printf("running...\n");
#ifdef UNIX_STYLE
gettimeofday(&t1, NULL);
#endif
#ifdef BCCWIN
t1=clock();
#endif
for (i=1;i<101;i++) {
davePrepareReadRequest(dc, &p);
daveAddVarToReadRequest(&p,daveInputs,0,0,6);
daveAddVarToReadRequest(&p,daveFlags,0,0,6);
daveAddVarToReadRequest(&p,daveFlags,0,6,6);
daveAddVarToReadRequest(&p,bmArea,areaNumber,4,54);
daveAddVarToReadRequest(&p,bmArea,areaNumber,4,4);
res=daveExecReadRequest(dc, &p, NULL);
if (res!=0) printf("\nerror %d=%s\n",res,daveStrerror(res));
if (i%10==0) {
printf("...%d",i);
fflush(stdout);
}
}
#ifdef UNIX_STYLE
gettimeofday(&t2, NULL);
usec = 1e6 * (t2.tv_sec - t1.tv_sec) + t2.tv_usec - t1.tv_usec;
usec/=1e6;
#endif
#ifdef BCCWIN
t2=clock();
usec = 0.001*(t2 - t1);
#endif
printf(" 100 reads took %g secs.\n",usec);
printf(" retries: 2nd %d 3rd %d\n",seconds, thirds);
}
void wBenchmark(daveConnection * dc,int bmArea) {
int i, c, areaNumber, maxWriteLen;
double usec;
#ifdef UNIX_STYLE
struct timeval t1, t2;
#endif
#ifdef BCCWIN
clock_t t1, t2;
#endif
maxWriteLen=dc->maxPDUlength-28;
areaNumber=0;
if(bmArea==daveDB) areaNumber=1;
printf("Now going to do write benchmark with minimum block length of 1.\n");
wait();
#ifdef UNIX_STYLE
gettimeofday(&t1, NULL);
#endif
#ifdef BCCWIN
t1=clock();
#endif
for (i=1;i<101;i++) {
daveWriteBytes(dc, bmArea, areaNumber,0,1,&c);
if (i%10==0) {
printf("...%d",i);
fflush(stdout);
}
}
#ifdef UNIX_STYLE
gettimeofday(&t2, NULL);
usec = 1e6 * (t2.tv_sec - t1.tv_sec) + t2.tv_usec - t1.tv_usec;
usec/=1e6;
#endif
#ifdef BCCWIN
t2=clock();
usec = 0.001*(t2 - t1);
#endif
printf(" 100 writes took %g secs. \n",usec);
printf("Now going to do write benchmark with shurely supported block length %d.\n",maxWriteLen);
wait();
#ifdef UNIX_STYLE
gettimeofday(&t1, NULL);
#endif
#ifdef BCCWIN
t1=clock();
#endif
for (i=1;i<101;i++) {
daveWriteBytes(dc, bmArea, areaNumber, 0, maxWriteLen, &c);
if (i%10==0) {
printf("...%d",i);
fflush(stdout);
}
}
#ifdef UNIX_STYLE
gettimeofday(&t2, NULL);
usec = 1e6 * (t2.tv_sec - t1.tv_sec) + t2.tv_usec - t1.tv_usec;
usec/=1e6;
#endif
#ifdef BCCWIN
t2=clock();
usec = 0.001*(t2 - t1);
#endif
printf(" 100 writes took %g secs. \n",usec);
wait();
}
/*
Changes:
03/18/2005 introduced bmArea parameter. S7-200 doesn't have enough Merkers/Flags for long
block benchmarks. Must use V memory. This is like DB1 of S7-300/400, but a CPU
may have a DB1 or not depending on program. So in case of 300/400 use Merker/Flag
memory.
*/