From: "Florian G. Pflug" Date: 2001-08-19T03:53:07+09:00 Subject: [ruby-talk:19983] Re: Slow file I/O? (newbie) On Sat, Aug 18, 2001 at 12:58:31PM +0900, Bil Kleb wrote: > So we were trying to test the speed of mirrored versus non-mirrored > disks and decided to use Ruby to do the testing. We wrote a couple > one-liners to write and read a Gigabyte-sized file of all 1's, viz, > > File.open("testFile","w") { |f| (2**30).times{f.putc "1"} } > > and > > File.open("testFile") { |f| (2**30).times{f.getc} } > > but we found the writing was so slow that we abandoned all hope > before we even got around to the reading part... If you write every byte using putc, you measure how fast your cpu can switch between user and kernel-mode - and not really the speed of your disks. I thing the best would be to measure at different block sizes - and if you ommit the smaller ones, I think you can use ruby for your tests. try something like this: data_str = "1" * (2**16) File.open("testFile", "w") { |file| (2**14).times {file.puts data_str} } "time" produces the following output on my athlon/500 real 1m5.342s user 0m1.040s sys 0m23.120s the following c-program: int main() { char *data_str ; int i ; FILE *handle ; data_str = (char *)malloc(65536) ; for(i=0; i<65536; i++) data_str[i] = '1' ; handle = fopen("testFile", "w") ; for(i=0; i<16384; i++) fwrite(data_str, 65536, 1, handle) ; fclose(handle) ; return 0 ; } produces this: real 1m5.856s user 0m0.300s sys 0m16.040s I guess you can ignore the "real" times, since my system was running xfree, gnone, sawfisch,... during the test, but as you can see the "user" value is always much smaller than the "sys" value. So most time is spent in the kernel, and the language you use doesn't really matter. greetings, Florian Pflug