Reading the accetped answer of the question locate vs find: usage, pros and cons of each other which tells that locate
's main advantage is speed I wanted to do some testing, whether I can benefit from its usage.
My first step was to estimate the speed of find
tool when providing a comparable service as locate
(hence only searching filenames, no extras).
I was surprised to see that
time find / 2>/dev/null >/dev/null
which I assumed iterates over all files (depended on the users permissions), showed
real 0m1.231s
user 0m0.353s
sys 0m0.867s
a rather quick result.
My question is if the applied command is a way to actually benchmark the speed of find
?
An aspect of the question I would be interested to have answered would be if there are some sort of buffers in the filesystem, hence in the OS (which is a linux kernel), which would impact the result?
My results where that droping the caches via echo 3 > /proc/sys/vm/drop_caches
, vastly increased the speed of find
:
$ sudo bash -c "echo 3 > /proc/sys/vm/drop_caches"
$ time (find / 2>/dev/null >/dev/null)
real 0m24.290s
user 0m1.143s
sys 0m8.230s
Yet on my linux system subsequent usage of find
returned to similar to mlocate
speeds of about 1sec?
Summed up, I am interested to know a way to benchmark the find command (to compare with locate)
Update/Remark
While the question was motivated by another one comparing locate
with find
and I ask about measuring/benchmarking the speed of find
I am aware that is is highly unlikely that data gathering from the live OS/filesystem (i.e. find
) , would be faster then a lookup within a database lookup (i.e. locate
). With the rather good caching behaviour of my operation systems kernel I nonetheless had rather similar execution times for searching via find
or locate
.
The question hence boils down to whether it is enough to drop the operation systems (filesystem) caches, to simulate the "actual" time needed for a find
done at a cold start and furthermore how realistic it would be to assume that those speed enhancing caches persists (not unsimilar to the updatedb
locate
database file) for all subsequent find
calls.
find
or that you intent to hint that there is no possible way for such a benchmark? Both would make a good starting point for an answer – humanityANDpeace Jan 05 '17 at 16:00/dev/null
to see what's actually going on. Expect permission errors as I mentioned, which are most likely since you are apparently no logged in as root. – Julie Pelletier Jan 05 '17 at 16:03strace
you will be able to see all the function calls of them, maybe it is useful for you. Take a look to the strace man. – Zumo de Vidrio Jan 05 '17 at 16:08/
is found and piped the output/dev/null/
as I did not want to cause distortion (i.e. a measuring of output buffer handling performance) when focus should have been the iteration from find. I will take your adivice though and check if permission errors are creating sort of unpredictable results – humanityANDpeace Jan 05 '17 at 16:14