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


In reply to Re: Re: Java vs. Perl file I/O benchmarks; valid test? by danboo
in thread Java vs. Perl file I/O benchmarks; valid test? by meonkeys

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.