in reply to Re: Java vs. Perl file I/O benchmarks; valid test?
in thread Java vs. Perl file I/O benchmarks; valid test?
Source for X2.java:[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
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.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(); } } }
Cheers
- danboo
|
---|