#include <stdio.h> #include <string.h> #include <fcntl.h> #include <errno.h> int main(int args, char **argv) { char file_name[255], file_name_use[255]; int fp; int num, num2, org_num; if (args != 3) return 0; memcpy(file_name, argv[1], strlen(argv[1])+1); org_num = num = atoi(argv[2]); num2 = num/1000; for (; num >= 0; num--) { if (num2 > 0) if ((num%num2) == 0) { printf("\rHas done %.2f%%", ((float)(org_num-num)/(float)org_num*100.0)); fflush(stdout); } sprintf(file_name_use, "%s_%d", file_name, num); if ((fp = open(file_name_use, O_RDWR | O_CREAT)) < 0) { fprintf(stderr, "Fail to creat %s\nError_Info: %s\n", file_name, strerror(errno)); return 0; } else { fchmod(fp, 0000644); write(fp, file_name_use, strlen(file_name_use)); close(fp); } } printf("\nAll files have been created\n"); return 0; } cc -O 2 file_create.c $ time ./a.out /tmp/test/test 50000 Has done 100.00% All files have been created real 0m46.980s user 0m0.101s sys 0m2.458s FreeBSD mybsd 7.0-RELEASE-p7 FreeBSD 7.0-RELEASE-p7 #0: Sun Dec 21 12:33:45 UTC 2008 root@i386-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC i386 % time ./a.out /tmp/test/test 50000 Has done 100.00% All files have been created 0.096u 2.525s 0:47.98 5.4% 5+1163k 0+102053io 0pf+0w % time ./a.out /tmp/test/test 50000 Has done 100.00% All files have been created 0.083u 2.558s 0:48.01 5.4% 5+1137k 0+102053io 0pf+0w cc -v Using built-in specs. Target: i386-undermydesk-freebsd Configured with: FreeBSD/i386 system compiler Thread model: posix gcc version 4.2.1 20070719 [FreeBSD] gentoo linux 下 reiserfs 文件系統 類型 容量 已用 可用 已用% 掛載點 /dev/mapper/gvg-lvhome reiserfs 9.0G 7.6G 1.5G 85% /home time ./test /home/axlrose/temp/1/test_/test 50000 Has done 100.00% All files have been created real 0m6.604s user 0m0.095s sys 0m5.790s gcc --version gcc (Gentoo 4.3.2-r3 p1.6, pie-10.1.5) 4.3.2 Copyright © 2008 Free Software Foundation, Inc. 本程序是自由軟件;請參看源代碼的版權聲明。本軟件沒有任何擔保; 包括沒有適銷性和某一專用目的下的適用性擔保。 FreeBSD安裝在80G的IDE硬盤上, gentoo安裝在 250G的sata硬盤上, reiserfs v3 從新找到ide的lvm+reiserver v3 分區 $ time ./test /home/idelvdata/test/test 50000 Has done 100.00% All files have been created real 0m7.072s user 0m0.100s sys 0m6.222s 以上 idelvdata 爲ide硬盤,測試結果看來跟 sata的差很少