Why is MacOS ~4x slower to open files than an Ubuntu VM on the same machine here?
A MWE using similar settings to the code this behavior was discovered on
#include <stdio.h>
#include <fcntl.h>
#include <time.h>
int main()
{
struct timespec tstart={0,0}, tend={0,0};
clock_gettime(CLOCK_MONOTONIC, &tstart);
int fd = open("/path/to/testfile.txt", O_RDONLY | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
clock_gettime(CLOCK_MONOTONIC, &tend);
printf("%.0f µs\n", (((double)tend.tv_sec + 1.0e-9*tend.tv_nsec) - ((double)tstart.tv_sec + 1.0e-9*tstart.tv_nsec)) * 1.0e6);
return 0;
}
MacOS 10.15.7, no SIP, no file vault, on a MacBook Pro with an SSD
51 µs
46 µs
49 µs
30 µs
46 µs
Ubuntu 20.04 VM (parallels) on the same machine
12 µs
12 µs
12 µs
13 µs
13 µs