2017-02-15 13:40 GMT+01:00 Cecil Westerhof <[email protected]>:
> I wrote the following Bash script:
>
I wrote a better one. See end of post.
Inprinciple you are only interested in the totals. I also changed the runs
from 10 to 25.
The OR version is the least efficient and it look likes the BETWEEN version
2 is the most efficient. It looks like it uses less user and more sys.
The results of two runs:
Timing OR version
real: 7.345
user: 6.688
sys: 0.648
Timing ABS version
real: 6.403
user: 5.56
sys: 0.84
Timing NOT BETWEEN version
real: 6.382
user: 5.62
sys: 0.752
Timing NOT BETWEEN version 2
real: 6.291
user: 5.488
sys: 0.788
and:
Timing OR version
real: 7.228
user: 6.496
sys: 0.728
Timing ABS version
real: 6.647
user: 5.904
sys: 0.74
Timing NOT BETWEEN version
real: 6.431
user: 5.688
sys: 0.736
Timing NOT BETWEEN version 2
real: 6.263
user: 5.492
sys: 0.756
The script:
#!/usr/bin/env bash
set -o errexit
set -o nounset
declare -r COUNT=25
declare -r DISPLAY_ALL=F
declare -r SELECT='
SELECT date
, time
, usertime
, systemtime
, idletime
, waittime
, stolentime
, (usertime + systemtime + idletime + waittime + stolentime) AS
totaltime
FROM vmstat
'
declare -r ABS_VERSION="
${SELECT}
WHERE ABS(100 - totaltime) > 1
;"
declare -r OR_VERSION="
${SELECT}
WHERE totaltime < 99 OR totaltime > 101
;"
declare -r NOT_BETWEEN_VERSION="
${SELECT}
WHERE totaltime NOT BETWEEN 99 AND 101
;"
declare -r NOT_BETWEEN_VERSION2="
${SELECT}
WHERE NOT (totaltime BETWEEN 99 AND 101)
;"
function timeQuery {
for i in $(seq ${COUNT}) ; do
sqlite3 ~/Databases/general.sqlite <<EOT
.timer on
.output /dev/null
${1}
EOT
done
}
function totalTimes {
declare output=$(timeQuery "${1}")
if [[ ${DISPLAY_ALL} == 'T' ]] ; then
printf "${output}\n"
fi
printf "${output}" | awk '
END {
print "real: " real
print "user: " user
print "sys: " sys
}
{
real += $4
user += $6
sys += $8
}
'
}
printf "Timing OR version\n"
totalTimes "${OR_VERSION}"
printf "\n\nTiming ABS version\n"
totalTimes "${ABS_VERSION}"
printf "\n\nTiming NOT BETWEEN version\n"
totalTimes "${NOT_BETWEEN_VERSION}"
printf "\n\nTiming NOT BETWEEN version 2\n"
totalTimes "${NOT_BETWEEN_VERSION2}"
--
Cecil Westerhof
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users