forked from david-slatinek/c-read-vs.-mmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.sh
221 lines (189 loc) · 5.61 KB
/
script.sh
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/bin/bash
file_sizes=(512 2k 8k 32k 128k 512k 1M 8M 32M 256M 1G)
buffer_sizes=(512 1024 4096 8192 16384)
help() {
echo "NAME"
echo -e "\tRun specific ./main test\n"
echo -e "SYNOPSIS"
echo -e "\tbash script.sh <flags>"
echo -e "\tchmod +x script.sh => ./script.sh <flags>"
echo -e "\nFLAGS"
echo "-h"
echo -e "\tPrint help"
echo "-c"
echo -e "\tCreate test files"
echo "-n [number]"
echo -e "\tPerform specific 'number' of rounds; 'number' > 1"
echo -e "\tDefault is 10"
echo "-r"
echo -e "\tRun 'read' test"
echo "-d"
echo -e "\tRun 'fread' test"
echo "-m"
echo -e "\tRun 'mmap' test"
}
create_files() {
rm -rf test_files
mkdir test_files
cd test_files || exit
for i in "${file_sizes[@]}"; do
echo "Generating file_${i}.txt ..."
base64 /dev/urandom | head -c "$i" >file_"$i".txt
echo -e "Generated file_${i}.txt\n"
done
cd ..
}
run_read() {
rm -rf read_results
mkdir read_results
make clean >>/dev/null
make >>/dev/null
n=$1
echo 1 | sudo tee /proc/sys/vm/drop_caches >>/dev/null
for i in "${file_sizes[@]}"; do
echo "Starting with read_${i}.txt ..."
touch read_results/read_"$i".txt
for j in "${buffer_sizes[@]}"; do
echo 1 | sudo tee /proc/sys/vm/drop_caches >>/dev/null
total_time=0
echo "buffer_size:${j}" >>read_results/read_"$i".txt
for z in $(seq -f "%0${#n}g" 1 "$n"); do
time_taken=$(./main -t -r "$j" test_files/file_"$i".txt | awk '{printf "%f", $1 * 1000}')
total_time=$(echo "$total_time $time_taken" | awk '{printf "%f", $1 + $2}')
echo "${z}:${time_taken}" >>read_results/read_"$i".txt
done
{
echo "total_time:${total_time}"
echo "average_time:$(echo "$total_time $n" | awk '{printf "%f", $1 / $2}')"
printf "\n"
} >>read_results/read_"$i".txt
done
echo -e "Done with read_${i}.txt\n"
sed -i '$d' "read_results/read_${i}.txt"
done
}
run_fread() {
rm -rf fread_results
mkdir fread_results
make clean >>/dev/null
make >>/dev/null
n=$1
echo 1 | sudo tee /proc/sys/vm/drop_caches >>/dev/null
for i in "${file_sizes[@]}"; do
echo "Starting with fread_${i}.txt ..."
touch fread_results/fread_"$i".txt
for j in "${buffer_sizes[@]}"; do
echo 1 | sudo tee /proc/sys/vm/drop_caches >>/dev/null
total_time=0
echo "buffer_size:${j}" >>fread_results/fread_"$i".txt
for z in $(seq -f "%0${#n}g" 1 "$n"); do
echo "command to work: ./main -t -d "$j" test_files/file_"$i".txt"
time_taken=$(./main -t -d "$j" test_files/file_"$i".txt | awk '{printf "%f", $1 * 1000}')
echo "time_taken:${time_taken}"
total_time=$(echo "$total_time $time_taken" | awk '{printf "%f", $1 + $2}')
echo "${z}:${time_taken}" >>fread_results/fread_"$i".txt
done
{
echo "total_time:${total_time}"
echo "average_time:$(echo "$total_time $n" | awk '{printf "%f", $1 / $2}')"
printf "\n"
} >>fread_results/fread_"$i".txt
done
echo -e "Done with fread_${i}.txt\n"
sed -i '$d' "fread_results/fread_${i}.txt"
done
}
calculate_deviations() {
chmod u+x main.py
echo "Calculating standard deviations ..."
for i in "${file_sizes[@]}"; do
./main.py -r "$1" -f "${2}_results/${2}_${i}.txt"
done
echo "Done with calculating standard deviations"
}
run_mmap() {
rm -rf mmap_results
mkdir mmap_results
make clean >>/dev/null
make >>/dev/null
n=$1
echo 1 | sudo tee /proc/sys/vm/drop_caches >>/dev/null
for i in "${file_sizes[@]}"; do
echo "Starting with mmap_${i}.txt ..."
total_time=0
touch mmap_results/mmap_"$i".txt
for j in $(seq -f "%0${#n}g" 1 "$n"); do
time_taken=$(./main -tm test_files/file_"$i".txt | awk '{printf "%f", $1 * 1000}')
total_time=$(echo "$total_time $time_taken" | awk '{printf "%f", $1 + $2}')
echo "${j}:${time_taken}" >>mmap_results/mmap_"$i".txt
done
{
echo "total_time:${total_time}"
echo "average_time:$(echo "$total_time $n" | awk '{printf "%f", $1 / $2}')"
} >>mmap_results/mmap_"$i".txt
echo -e "Done with mmap_${i}.txt\n"
done
}
if [[ -z "$*" ]]; then
help
exit 0
fi
c_flag=false
r_flag=false
d_flag=false
m_flag=false
n_arg=10
while getopts "hcrdmn:" opt; do
case $opt in
h)
help
exit 0
;;
c)
c_flag=true
;;
r)
r_flag=true
;;
m)
m_flag=true
;;
d)
d_flag=true
;;
n)
n_arg="$OPTARG"
if ! [[ "$n_arg" =~ ^[0-9]+$ ]]; then
echo "Argument must be a number"
exit 1
fi
if [ "$n_arg" -lt 1 ]; then
echo "Argument must be greater than 0"
exit 1
fi
;;
*)
printf "\n"
help
exit 1
;;
esac
done
if [[ $c_flag = true ]]; then
create_files
fi
if [[ $r_flag = true ]]; then
run_read "$n_arg"
calculate_deviations "$n_arg" "read"
make clean >>/dev/null
fi
if [[ $d_flag = true ]]; then
run_fread "$n_arg"
calculate_deviations "$n_arg" "fread"
make clean >>/dev/null
fi
if [[ $m_flag = true ]]; then
run_mmap "$n_arg"
calculate_deviations "$n_arg" "mmap"
make clean >>/dev/null
fi