From: Brian Candler Date: 2003-04-08T06:25:51+09:00 Subject: Re: Newbie question:read file speed --qDbXVdCdHGoSgWSk Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Apr 07, 2003 at 09:21:04PM +0900, ts wrote: > See [ruby-talk:68578] > > ruby168 BIG = 319 > ruby168 SMALL = 95 > > ruby18p2 BIG = 12 > ruby18p2 SMALL = 12 Oh I'm not arguing that ruby 1.8p2 isn't better than ruby 1.6.8. I believe that those tests were done under Windows, and that just shows how dreadful Windows I/O libraries are. Under FreeBSD I see almost zero difference between ruby 1.6.8 and ruby 1.8p2 for the attached program, showing that a real operating system comes with decent I/O libraries. Perl is still nearly twice as fast as ruby though: [brian@vaio ruby]$ time ruby x.rb /usr/share/dict/words Elapsed = 2.146236062 real 0m2.492s user 0m2.362s sys 0m0.120s [brian@vaio ruby]$ time perl x.pl /usr/share/dict/words Elapsed = 1 real 0m1.347s user 0m1.251s sys 0m0.080s However evil or optimised perl's I/O libraries are, I doubt that that's the reason for the difference. Regards, Brian. --qDbXVdCdHGoSgWSk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="x.rb" filename=ARGV[0] lc = 0 starttime = Time.now.to_f File.open(filename).each_line do lc += 1 end stoptime = Time.now.to_f puts "Elapsed = " + (stoptime - starttime).to_s --qDbXVdCdHGoSgWSk Content-Type: application/x-perl Content-Disposition: attachment; filename="x.pl" Content-Transfer-Encoding: quoted-printable my $filename=3D$ARGV[0];=0Amy $lc =3D 0;=0Amy $starttime =3D time;=0Aopen F= ILE,"<$filename";=0Awhile () {=0A $lc++;=0A}=0Amy $stoptime =3D time;= =0A =0Aprint "Elapsed =3D ", ($stoptime - $starttime), "\n"=0A --qDbXVdCdHGoSgWSk--