A few measurements of stat()'s speed

Bastiaan Veelo Bastiaan at Veelo.net
Wed Mar 27 22:52:09 UTC 2019


On Wednesday, 27 March 2019 at 12:06:11 UTC, Andrei Alexandrescu 
wrote:
> On 3/27/19 5:23 AM, Bastiaan Veelo wrote:
>> On Tuesday, 26 March 2019 at 18:06:08 UTC, Andrei Alexandrescu 
>> wrote:
>>> On a Linux moderately-loaded local directory (146 files) 
>>> mounted from an SSD drive, one failed stat() takes only about 
>>> 0.5 microseconds. That means e.g. if a module imports std.all 
>>> (which fails 142 times), the overhead accountable to failed 
>>> stat() calls is about 70 microseconds, i.e. negligible.
>> 
>> It could be interesting to know whether timings on Windows are 
>> more significant. If only I knew how to measure this within 10 
>> minutes...
>> 
>> Bastiaan.
>
> Really simple. Here's the C code Eduard and I used. Run it a 
> few times with a variety of paths (change of course to use 
> Windows naming) and divide total run time by n.
>
> #include<stdio.h>
> #include<string.h>
> #include<sys/stat.h>
> #include <sys/types.h>
> #include <fcntl.h>
>
> int main(int argc, char** argv)
> {
>     size_t i;
>     size_t n = 1000000;
>     const char* s = "/home/user/gd/Google Photos/xyz";
>     //s = "/home/user/dir/xyz";
>     //s = "/run/user/1000/gvfs/mount/xyz";
>
>     struct stat sfile;
>     for (i = 0; i < n; ++i)
>     {
>       stat(s, &sfile);
>     }
>     return 0;
> }

On Windows 10, i7-7700HQ, M.2 SSD, provided I did things right, I 
get ca. 40x worse timings. Compiled with MSVC 2017, no options 
(cl teststat.c). Timed in PowerShell using `Measure-Command 
{.\teststat.exe}`.

For "/home/user/gd/Google Photos/xyz", a directory that does not 
exist, total running time is 17 seconds (+/- 0.2).

For "/Users/bastiaan/Documents/D/tests/stat/teststat.c", an 
existing file in a directory with two other files, total running 
time is a whopping 44 seconds (+/- 1.0).

For "/Coin/Coin_source/src/nodes/xyz", a nonexisting file in an 
existing directory with 114 items, total running time is 19.5 
seconds (+/- 1.0). So for me, 142 failed stats cost close to 2.8 
milliseconds.

Bastiaan.


More information about the Digitalmars-d mailing list