From: Greg Brondo Date: 2003-04-03T00:51:28+09:00 Subject: Re: Newbie question:read file speed Here they are: ------- RUBY ------ filename = ARGV[0] lc = 0 starttime = Time.now.to_f File.open(filename).each_line do lc += 1 if lc % 1000 == 0 puts "Read #{lc} lines" end end stoptime = Time.now.to_f puts "Elapsed = " + (stoptime - starttime).to_s ---------------------------------------------- ------ PYTHON ------ import sys, time filename = sys.argv[1] fh = open(filename,'r') lc = 0 starttime = time.time() for line in fh: lc += 1 if lc % 1000 == 0: print "Read %d lines" % lc fh.close() stoptime = time.time() print "Elapsed = %d" % (stoptime - starttime ----------------------------------------------------- ------ JAVA ------ import java.util.*; import java.io.*; class Test { public static void main(String[] args) { try { BufferedReader in = new BufferedReader(new FileReader(args[0])); int lc = 0; String line; long starttime = System.currentTimeMillis() / 1000; while ( (line = in.readLine()) != null ) { lc += 1; if ( (lc % 1000) == 0 ) { System.out.println("Read " + lc + " lines"); } } in.close(); long stoptime = System.currentTimeMillis() / 1000; System.out.println("Elapsed = " + (stoptime - starttime)); } catch (Exception e) { e.printStackTrace(); } } ------------------------------------------------- The stats for reading a text file with 1,572,000 lines in an CMD.EXE console (on a PIII 866 w 512MB): RUBY (1.8p2): 13.5 sec PYTHON (2.3b2): 4 sec JAVA (1.4.1): 7 sec Thanks for the help!!! Greg B. "Brian Candler" wrote in message news:20030402110858.C19790@linnet.org... > On Wed, Apr 02, 2003 at 07:28:20AM +0900, Greg Brondo wrote: > > Why is ruby (on windows) so much slower at reading lines in a file (as > > compared to perl, python or java) ? I've installed 1.8 preview 2 and it's > > much faster but still not nearly as fast as the other languages mentioned. > > Can you post the exact programs that you are timing in each language? > > Regards, > > Brian. >