• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Best way to get record counts?

 
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good evening!

Is there a more efficient way to get record counts other than actually reading each record into the buffer, ie:
lineu = textReader.readLine?

Thanks again!
bc

if(filename.indexOf(".TXT.out")>-1 && typ.equals(".TXT.out") )
{
try
{
BufferedReader textReader = new BufferedReader(new FileReader(filename));
String lineu = null;
while ((lineu = textReader.readLine()) != null)
{
if(filename.indexOf("BQ")>-1) rcqcnt++;
if(filename.indexOf("XS")>-1) rcscnt++;
if(filename.indexOf("MS")>-1) rmstrcnt++;
read_cnt++;
}
textReader.close();
System.out.println(filename+" "+read_cnt);
}
catch(Exception e){System.out.println("reading excpection xx:"+e);}
}
}
 
bob connolly
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I quess what i'm trying to figure out is how to make my Java record count program work as fast as an equivalent PERL program. This Perl program must be avoiding the loading of the record somehow maybe? because it runs at least 2X faster than the JAVA program and i'd prefer to use JAVA for this process!

#!/usr/bin/perl

$filename = $ARGV[0];

#open the list of files
open (FILE_IN,$filename) || die ("Open Failed1: $!\n");


while (defined($infile=<FILE_IN> ) {
print "$infile\n";
chomp ($infile);
open (IN,$infile) || die ("Open Failed2: $!\n");
while (defined($line=<IN> ) {
$nlines++; # counts the lines
}
}
close IN;
close FILE_IN;
print "rows: $nlines\n";
 
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bob - Couple of points.

All three of your if statements like:



can be moved outside the 'while' loop, can they not?

Second, the default buffer used by a BufferedReader (in 1.5) is 8192 bytes. Try doubling that number, or maybe quadrupling it:



Guy
 
bob connolly
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks alot Guy! appreciate the help!

bc
 
Tick check! Okay, I guess that was just an itch. Oh wait! Just a tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic