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
|