in reply to Java vs. Perl file I/O benchmarks; valid test?

I wonder if the new capabilities of the newly released JDK 1.4 would affect the outcome. It now supports memory mapped I/O. See the 'java.nio.*' package.

Cheers,

- danboo

  • Comment on Re: Java vs. Perl file I/O benchmarks; valid test?

Replies are listed 'Best First'.
Re: Re: Java vs. Perl file I/O benchmarks; valid test?
by danboo (Beadle) on Feb 28, 2002 at 21:50 UTC
    Ok, i whipped up a version using JDK 1.4 and the java.nio package. It's faster than either of the other versions on my system.

    [danboo@danboo 04:37pm ~/java]$ java X ten_meg_file__2.txt out__2 Time = 492 Buf Time = 432 [danboo@danboo 04:37pm ~/java]$ perl X.pl ten_meg_file__2.txt out__2 0.192673087120056 Seconds Elapsed. [danboo@danboo 04:37pm ~/java]$ java X2 ten_meg_file__2.txt out__2 Time = 128
    Source for X2.java:
    import java.io.*; import java.nio.*; import java.nio.channels.*; public class X2 { public static void main (String [] args) { try { long l = System.currentTimeMillis(); FileInputStream input = new FileInputStream(args[0]); FileOutputStream output = new FileOutputStream(args[1]); FileChannel inputChannel = input.getChannel(); FileChannel outputChannel = output.getChannel(); int inputLength = (int) inputChannel.size(); MappedByteBuffer buffer = inputChannel.map(FileChannel.MapMode.R +EAD_ONLY, 0, inputLength); outputChannel.write(buffer); System.out.println("Time = "+ (System.currentTimeMillis()-l)); } catch (Exception e) { e.printStackTrace(); } } }
    Note: This is my first time using the new 'java.nio' package for memory mapped file operations. There may be better ways to do it. I don't necessarily believe these tests are accurate.

    Cheers

    - danboo

Re: Re: Java vs. Perl file I/O benchmarks; valid test?
by simon.proctor (Vicar) on Feb 28, 2002 at 21:24 UTC
    For those who are interested look at the java.nio.channel for a comparison. The reading on the FileChannel class is interesting as it covers this specific topic.

    It does some quite nice things with optimising access to large files. However as I have only just downloaded it I couldn't say if its great or quicker than Perl even. Not that I really mind either way :)