forked from sysprog21/prefix-search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.c
130 lines (114 loc) · 3.53 KB
/
bench.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include <glib.h>
#include <assert.h>
#define IN_FILE "cities.txt"
#define MYMIN(a,b) (((a)<(b))?(a):(b))
int main()
{
char line[128];
int getLenth,strLenth;
unsigned int all = 0,time = 0;
struct timespec ts;
puts("reopen success");
FILE *cities = fopen(IN_FILE, "r");
FILE *output = fopen("test.txt", "w");
fscanf(cities, "%s", line);
//printf("%ld\n", g_utf8_strlen(line,-1));
do {
clock_gettime(CLOCK_REALTIME, &ts);
//getLenth = (((int)ts.tv_nsec) >> 2) && 0x00000001; // 1 or 0
if((((int)ts.tv_nsec) >> 2) & 1) {
strLenth = (((int)ts.tv_nsec) & 6) + 1;
strLenth = MYMIN(strLenth,(int)g_utf8_strlen(line,-1));
*(g_utf8_offset_to_pointer (line,(long) strLenth)) = '\0';
fprintf(output, "s\n");
fprintf(output, "%s\n", line);
}
} while(fscanf(cities, "%s", line) != EOF);
fprintf(output, "q\n");
fclose(cities);
fclose(output);
// make test input success
puts("cpy start");
fflush(stdout);
fflush(stdin);
assert(freopen("output.txt","w",stdout) &&
"stdout freopen fail");
assert(freopen("test.txt","r",stdin) &&
"stdin freopen fail");
system("./test_cpy");
fflush(stdout);
fflush(stdin);
;
assert(freopen("output2.txt","w",stdout) &&
"stdout freopen fail");
assert(freopen("test.txt","r",stdin) &&
"stdin freopen fail");
system("./test_ref");
fclose(stdout);
fclose(stdin);
int clock;
int avg1 = 0,time1 = 0 , avg2 =0 ,time2 =0;
cities = fopen("output.txt", "r");
output = fopen("clock.txt", "w");
fscanf(cities, "%s", line);
do {
if(strcmp(line, "Clock")!=0) {
} else {
fscanf(cities, "%d", &clock);
fprintf(output, "%d\n", clock);
avg1+=clock;
time1++;
}
} while(fscanf(cities, "%s", line) != EOF);
fclose(cities);
fclose(output);
cities = fopen("output2.txt", "r");
output = fopen("clock2.txt", "w");
fscanf(cities, "%s", line);
do {
if(strcmp(line, "Clock")!=0) {
} else {
fscanf(cities, "%d", &clock);
fprintf(output, "%d\n", clock);
avg2+=clock;
time2++;
}
} while(fscanf(cities, "%s", line) != EOF);
fclose(cities);
fclose(output);
output = fopen("avg.txt", "w");
fprintf(output, "CPY avg = %d\n", avg1/time1);
fprintf(output, "REF avg = %d\n", avg2/time2);
fclose(output);
/*output = fopen("avg.txt", "w");
//printf("all = %d time = %d \n",all,time );
fprintf(output, "%d\n",all/time);
fclose(output);/*
/*
if(freopen("BENCH_O.txt","w",stdout)==NULL)
printf("stdout freopen fail\n");
if(freopen("BENCH_I.txt","r+",stdin)==NULL)
printf("stdin freopen fail\n");
system("./print");
if(popen("./print","w"))
puts("success");
if(freopen("OUTPUT.txt","r",stdio)==NULL)
puts("reopen stdio success")
fgets(line, sizeof line, stdin);
*/
}
/*
流程
Make部份
1.MAKE 執行外部測試檔
2.外部測試檔重新產生 test.txt
3.外部測試freopen 並將stdio->test.txt stdout->out.txt
4.返回外部測試檔 外部測試檔讀取output.txt 取出clock部份資料並整理為clock.txt
5.MAKE 執行 caculate 計算標準差並取出信賴區間
編譯時必須使用 gcc bench.c `pkg-config --cflags --libs glib-2.0` -o bench
*/