https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91030
--- Comment #38 from Janne Blomqvist <jb at gcc dot gnu.org> --- First, I think there's a bug in the benchmark in comment #c20. It writes blocksize * sizeof(double), but then advances only blocksize for each iteration of the loop. Fixed version writing just bytes below: #include <sys/time.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/statvfs.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> double walltime (void) { struct timeval TV; double elapsed; gettimeofday(&TV, NULL); elapsed = (double) TV.tv_sec + 1.0e-6*((double) TV.tv_usec); return elapsed; } #define NAME "out.dat" #define N 250000000 int main() { int fd; unsigned char *p, *w; long i, size, blocksize, left, to_write; int bits; double t1, t2; struct statvfs buf; printf ("Test using %ld bytes\n", (long) N); statvfs (".", &buf); printf ("Block size of file system: %ld\n", buf.f_bsize); p = malloc(N * sizeof (*p)); for (i=0; i<N; i++) p[i] = i; for (bits = 10; bits < 27; bits++) { sync(); blocksize = 1 << bits; printf("bs = %10ld, ", blocksize); unlink (NAME); fd = open(NAME, O_WRONLY|O_CREAT, S_IRUSR | S_IWUSR); if (fd < 0) { perror ("Open of " NAME " failed"); exit(1); } left = N; w = p; t1 = walltime(); while (left > 0) { if (left >= blocksize) to_write = blocksize; else to_write = left; write (fd, w, blocksize); w += to_write; left -= to_write; } close (fd); t2 = walltime (); printf ("%.2f MiB/s\n", N / (t2-t1) / 1048576); } free (p); unlink (NAME); return 0; }