From: Greg Brondo Date: 2003-04-04T01:35:21+09:00 Subject: Re: Newbie question:read file speed Robert Klemme wrote: > Hi Greg, > > out of curiosity, could you test the attached Java class and tell us > whether it behaves differently than the one you provided? Thanks! > > Regards > > robert > > > ------------------------------------------------------------------------ > > package io; > > import java.io.BufferedInputStream; > import java.io.BufferedReader; > import java.io.FileInputStream; > import java.io.InputStreamReader; > > /** > * Read performance test. > * > * @author robert.klemme > * @created 03.04.2003 > * @version $Id$ > */ > public class Test { > > public static void main( String[] args ) { > try { > BufferedReader in = > new BufferedReader( > new InputStreamReader( > new BufferedInputStream( > new FileInputStream( args[0] ), 4096 ) ) ); > > 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(); > } > } > } Robert, tried the new Java class. Speed up read by about 4 seconds. BTW -- thanks all for answering my question. Here's my reason for asking in the first place: I really like the promise and application of Ruby so I'm trying to begin using it more and more in my daily work. I'm a Python hack (and a Java Hack as well) but I really like the cleaness and builtin regex that Ruby provides. Anyway, I'm going to run some more tests now with the same dataset without writing to the screen to see what I get. I'll post the results soon. Thanks again! Greg Brondo