A few measurements of stat()'s speed

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Mar 27 12:06:11 UTC 2019


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;
}




More information about the Digitalmars-d mailing list