On Thu, 7 Sept 2023 at 09:44, Bastian Bittorf <[email protected]> wrote:
> I understand your commands, but i do not understand
> how you are measuring the time,
The busybox time does not work for functions. A function is needed to
replicate the pidof basic behaviour otherwise the comparison can be
considered unfair.
redfishos:/rootfs # a=$(date +%s%N); time grep -E
"command1|command2|command3" /proc/[1-9]*/comm; b=$(date +%s%N);
c=$(date +%s%N); echo $(( (b-a) - (c-b) ))
Command exited with non-zero status 1
real 0m 0.05s
user 0m 0.01s
sys 0m 0.03s
80300209
redfishos:/rootfs # a=$(date +%s%N); time pidof command1 command2
command3; b=$(date +%s%N); c=$(date +%s%N); echo $(( (b-a) - (c-b) ))
Command exited with non-zero status 1
real 0m 0.28s
user 0m 0.02s
sys 0m 0.23s
294661666
redfishos:/rootfs # min=$(for i in $(seq 1 100); do b=$(date +%s%N);
c=$(date +%s%N); echo $(( c-b )); done | sort -g | head -n1); echo
$min
4220937
redfishos:/rootfs # a=$(date +%s%N); time grep -E
"command1|command2|command3" /proc/[1-9]*/comm; b=$(date +%s%N); echo
$(( (b-a) - min ))
Command exited with non-zero status 1
real 0m 0.05s
user 0m 0.00s
sys 0m 0.04s
81258907
redfishos:/rootfs # a=$(date +%s%N); time pidof command1 command2
command3; b=$(date +%s%N); echo $(( (b-a) - min ))
Command exited with non-zero status 1
real 0m 0.28s
user 0m 0.02s
sys 0m 0.23s
290395104
However, using time with grep and pidof for a confrontation still
brings the same result. The grep is O(1) while the pidof is O(N).
cmd=""; for i in $(seq 0 9); do cmd="${cmd:-} command$i"; a=$(date
+%s%N); time pidof $cmd 2>&1 | grep real; b=$(date +%s%N); echo $((
(b-a) - min )); done
real 0m 0.09s
106920365
real 0m 0.18s
198038438
real 0m 0.28s
291350782
real 0m 0.37s
388994896
real 0m 0.46s
479455261
real 0m 0.55s
564525573
real 0m 0.64s
658862240
real 0m 0.74s
750989739
real 0m 0.83s
843974480
real 0m 0.92s
935911458
redfishos:/rootfs # echo $cmd | tr ' ' '|'
command0|command1|command2|command3|command4|command5|command6|command7|command8|command9
redfishos:/rootfs # time grep -E "command1" /proc/[1-9]*/comm 2>&1 | grep real
real 0m 0.05s
redfishos:/rootfs # time grep -E $(echo $cmd | tr ' ' '|')
/proc/[1-9]*/comm 2>&1 | grep real
real 0m 0.05s
This is a matter of fact whether grep vs pidof for a single argument -
the most probable case - would be faster or not. Moreover, grep shows
to be nearly 2x faster also with a single argument. While with 4
arguments is 7x (mine estimation was nearly 5x) faster and with 5
arguments is 9x faster (mine estimation was nearly 6x). This because
time showed us that grep is 1.6x faster than pidof when a single
argument is passed while my way - a conservative way of taking times -
was starting when n=1 with a 1:1 ratio.
The two ways to take measures showed a difference of 7 - 18% when
n(args) = 1 and 0.7 - 1.7% when n(args) = 10. This clearly a linear
regression which tells us that the main source of error stays in the
accuracy of the $min value which is an estimation. Therefore err(n) =
err(min) / n. Fortunately, this is a conservative way of taking
measures because I used the min value of 100. Conservative, it means
that I could have not appreciated a small difference in performances
between pidof and grep or a small difference in O(same). Such a small
difference in performance would not have attracted my attention, in
the first place and I would not have started to investigate the issue
using statistics. Hence, the HP of seeing a wide difference in
performance or in O(different) was acceptable from the beginning.
More in general, how to take measures and dealing with errors and
statistics are not common skills among IT guys unless they have a
degree/bachelor in applied physics (or a theoretical physic with
laboratories).
Best regards, R-
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox