/* * randfiles.c * * Usage: randfiles * * For benchmarking create performance - create files with * numbered names, in random order. The flag, if y, echoes * filenames created. For example, 'randfiles foo 10 y' will create * 10 empty files with names ranging from foo0 to foo9. * * copyleft: Daniel Phillips, Oct 6, 2001, phillips@nl.linux.org * */ #include #define swap(x, y) do { typeof(x) z = x; x = y; y = z; } while (0) int main (int argc, char *argv[]) { int n = (argc > 2)? strtol(argv[2], 0, 10): 0; int i, size = 50, show = argc > 3 && !strncmp(argv[3], "y", 1); char name[size]; int choose[n]; for (i = 0; i < n; i++) choose[i] = i; for (i = n; i; i--) { int j = rand() % i; swap(choose[i-1], choose[j]); } for (i = 0; i < n; i++) { snprintf(name, size, "%s%i", argv[1], choose[i]); if (show) printf("create %s\n", name); close(open(name, 0100)); } return 0; }