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...
We tried setting a variable instead of using "1", but it didn't
noticeably alter the speed.
What are we doing wrong?
(We're running Ruby 1.6.4 on Pentium II's and III's via GNU/Linux.)
For a MB file, i.e., 2**20, ruby -r profile testw.rb gives:
% cumulative self self total
time seconds seconds calls ms/call ms/call name
77.74 189.94 189.94 1 189940.00 244320.00 Fixnum#times
22.26 244.32 54.38 1048576 0.05 0.05 IO#putc
0.00 244.32 0.00 1 0.00 244320.00 File#open
0.00 244.32 0.00 1 0.00 0.00 Fixnum#<
0.00 244.32 0.00 1 0.00 0.00 Fixnum#**
0.00 244.32 0.00 1 0.00 244320.00 #toplevel
(BTW: it only takes 3 seconds without the profiling.)
The comparable c routine runs several orders of magnitude faster:
#include <stdio.h>
#include <math.h>
int main(){
FILE *outfile= fopen("ctestFile","w");
unsigned int i;
for (i=0; i<pow(2,30); ++i) fputc('1',outfile);
return 0;
}
Thanks in advance,
--
bil <http://abweb.larc.nasa.gov/~kleb/>