-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostgres.sh
executable file
·57 lines (48 loc) · 1.36 KB
/
postgres.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
#!/bin/bash
RED='\033[0;31m'
CYAN='\033[0;36m'
MAGENTA='\033[0;35m'
NC='\033[0m'
strategy='popcount'
base='bit_count'
trials=50
domain=500000
alignments="2048 4096 8192 15040 16384 32768 65536 131072"
units='false'
while getopts 's:t:a:x:uc' flag; do
case "${flag}" in
s) strategy=$OPTARG ;;
t) trials=$OPTARG ;;
d) domain=$OPTARG ;;
a) alignments=$OPTARG ;;
u) units='true' ;;
*) error "Unexpected option ${flag}" ;;
esac
done
printf "> Strategy: ${MAGENTA}$strategy${NC}\n"
printf "> Bit length: ${MAGENTA}$alignments${NC}\n"
printf "> Trials: ${MAGENTA}$trials${NC}\n\n"
read -a arr <<< "$alignments"
for alignment in "${arr[@]}"
do
printf "${CYAN}$alignment${NC} "
table="${base}_${alignment}_$(printf %07d $domain)"
query="SELECT sum(count) FROM (SELECT $strategy(bit) as count FROM $table WHERE True) as bits;"
for (( i=1; i<=$trials; i++ ))
do
case $units in
'true')
temp=$(echo "\\timing on \\\\ $query" | psql | grep "Time:" | sed s/"Time: "//)
;;
'false')
temp=$(echo "\\timing on \\\\ $query" | psql | grep "Time:" | grep -Eo -m 1 '[0-9]+([.][0-9]+)?' | head -1)
;;
esac
printf "$temp"
if [ $i -lt $trials ]
then
printf " "
fi
done
echo
done