• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Record count

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I want to know is there any efficient way to find out the number of records in the variable length text file.
I have tried 2 ways using BufferedReader & LineNumberReader but I am getting a same performance.To count 50,000 records both APIs taking 12 seconds.But is there any other way to calculate the above functionality.
Code ex
-------
System.out.println(new Date());
LineNumberReader in = new LineNumberReader(new FileReader("test.txt"));
while(in.readLine() != null);
System.out.println(in.getLineNumber());
System.out.println(new Date());
in.close();
System.out.println(new Date());
BufferedReader bf = new BufferedReader( new FileReader("test.txt"));
int count = 0;
while(bf.readLine() != null)
count++;
System.out.println(count);
System.out.println(new Date());
Thanks
Saran.
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The key here is to first of all use a lower level InputStream and then let parallel processing do the work for you:

I got a record count of 50034 on my test.txt (which I manufactured from some long system log files) in about 2 seconds on a P2-400 (a real slowpoke). So you should be able to cut this down to about a second.
Hope this helps.
 
saran sankar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much michal.
Saran.
 
reply
    Bookmark Topic Watch Topic
  • New Topic