-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·138 lines (100 loc) · 3.29 KB
/
test.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
#!/bin/sh
#############################################
#======= C O N F I G U R A T I O N S =======#
#############################################
locate_db="/tmp/test_mlocate.db"
kokatu_uncompressed_db="/tmp/test_kokatu.db"
kokatu_compressed_db="/tmp/test_kokatu_compressed.db"
kokatu_binary="./kokatu"
#############################################
#=== A U X I L I A R F U N C T I O N S ===#
#############################################
_exit_error() {
printf "\nERROR: %s\n" "$1" >&2
exit 1
}
_check_command() {
command -v "$1" >/dev/null || _exit_error "'$1' is not installed"
}
_disable_compression() {
sed -i 's/compression="Y"/compression=""/' "$kokatu_binary"
}
_enable_compression() {
sed -i 's/compression=""/compression="Y"/' "$kokatu_binary"
}
_disable_auto_removes() {
sed -i 's/rm/#rm/' "$kokatu_binary"
}
_enable_auto_removes() {
sed -i 's/#rm/rm/' "$kokatu_binary"
}
#############################################
#======= T E S T F U N C T I O N S =======#
#############################################
check_for_commands() {
printf "\nChecking for commands..."
_check_command rg
_check_command fd
_check_command lz4
_check_command locate
_check_command updatedb
_check_command perf
_check_command hyperfine
printf " OK\n"
}
create_databases() {
printf "\nCreating Databases\n"
sudo touch "$kokatu_uncompressed_db"
sudo touch "$kokatu_compressed_db"
sudo touch "$locate_db"
printf " Locate - "
perf stat sudo updatedb -o "$locate_db" 2>&1 >/dev/null | grep "time elapse" | awk '{print $1}'
_disable_auto_removes
_disable_compression
printf " Kokatu (no compression) - "
perf stat sudo $kokatu_binary -d "$kokatu_uncompressed_db" -u 2>&1 >/dev/null | grep "time elapse" | awk '{print $1}'
_enable_compression
printf " Kokatu (compression) - "
perf stat sudo $kokatu_binary -d "$kokatu_compressed_db" -u 2>&1 >/dev/null | grep "time elapse" | awk '{print $1}'
_disable_compression
_enable_auto_removes
}
print_entries_number() {
printf "\nEntries Number\n"
printf " Locate - "
locate -d "$locate_db" -c -r ".*"
printf " Kokatu (no compression) - "
$kokatu_binary -d "$kokatu_uncompressed_db" -c ".*"
printf " Kokatu (compression) - "
$kokatu_binary -d "$kokatu_compressed_db.lz4" -c ".*"
}
print_db_sizes() {
printf "\nDatabase Size\n"
printf " Locate - "
du -h "$locate_db" | awk '{print $1}'
printf " Kokatu (no compression) - "
du -h "$kokatu_uncompressed_db" | awk '{print $1}'
printf " Kokatu (compression) - "
du -h "$kokatu_compressed_db.lz4" | awk '{print $1}'
}
performance_test() {
printf "\nPerformance Test\n"
hyperfine --warmup 3 "locate -d $locate_db README.md" "$kokatu_binary -d $kokatu_uncompressed_db README.md" "$kokatu_binary -d $kokatu_compressed_db.lz4 README.md"
}
clean_up() {
printf "\nCleaning Up\n"
sudo rm "$locate_db"
sudo rm "$kokatu_uncompressed_db"
sudo rm "$kokatu_compressed_db"
}
#############################################
#================= M A I N =================#
#############################################
echo "Start Testing"
check_for_commands
create_databases
print_entries_number
print_db_sizes
performance_test
clean_up
printf "\nFinished\n"