<quote> (chapter 12)
Although the performance of “old” stream I/O has been improved by implementing it with nio, mapped file access tends to be dramatically faster.
</quote>
So by switching to 1.4 and *not* using NIO you're likely to get a speed bump already.
However switching to mapped file access (as was suggested before using memory mapped files) from traditional stream IO would gain the most significant increase.
<quote> Stream Write: 1719 Mapped Write: 359 Stream Read: 750 Mapped Read: 125 Stream Read/Write: 5188 Mapped Read/Write: 16 </quote>
I am getting similar results over various runs. The test program is attached (needs the test harness classes to run, but you can see what he's doing)
The third edition including code samples is freely available from http://mindview.net/Books/DownloadSites
I hope this helps making the decision 1.4 vs 1.3. I also started a poll on the userlist to get a feeling of what the installed userbase is using at the moment. I'll gather some stats and report back.
Regards Jorg
Antonio Gallardo wrote:
Hi:
Many was talked about this topic. I think it not need a large explanation:
The idea is to set JSDK 1.4 as the minimum supported JDK supported for the next major release 2.2 of Cocoon. Currently we are supporting also 1.3 but seems like few people is using it.
Do you agree with JSDK 1.4 as the lower Java version supported in Cocoon 2.2?
Here is my +1
Best Regards,
Antonio Gallardo
//: c12:MappedIO.java
// {Clean: temp.tmp}
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
public class MappedIO {
private static int numOfInts = 4000000;
private static int numOfUbuffInts = 200000;
private abstract static class Tester {
private String name;
public Tester(String name) { this.name = name; }
public long runTest() {
System.out.print(name + ": ");
try {
long startTime = System.currentTimeMillis();
test();
long endTime = System.currentTimeMillis();
return (endTime - startTime);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public abstract void test() throws IOException;
}
private static Tester[] tests = {
new Tester("Stream Write") {
public void test() throws IOException {
DataOutputStream dos = new DataOutputStream(
new BufferedOutputStream(
new FileOutputStream(new File("temp.tmp"))));
for(int i = 0; i < numOfInts; i++)
dos.writeInt(i);
dos.close();
}
},
new Tester("Mapped Write") {
public void test() throws IOException {
FileChannel fc =
new RandomAccessFile("temp.tmp", "rw")
.getChannel();
IntBuffer ib = fc.map(
FileChannel.MapMode.READ_WRITE, 0, fc.size())
.asIntBuffer();
for(int i = 0; i < numOfInts; i++)
ib.put(i);
fc.close();
}
},
new Tester("Stream Read") {
public void test() throws IOException {
DataInputStream dis = new DataInputStream(
new BufferedInputStream(
new FileInputStream("temp.tmp")));
for(int i = 0; i < numOfInts; i++)
dis.readInt();
dis.close();
}
},
new Tester("Mapped Read") {
public void test() throws IOException {
FileChannel fc = new FileInputStream(
new File("temp.tmp")).getChannel();
IntBuffer ib = fc.map(
FileChannel.MapMode.READ_ONLY, 0, fc.size())
.asIntBuffer();
while(ib.hasRemaining())
ib.get();
fc.close();
}
},
new Tester("Stream Read/Write") {
public void test() throws IOException {
RandomAccessFile raf = new RandomAccessFile(
new File("temp.tmp"), "rw");
raf.writeInt(1);
for(int i = 0; i < numOfUbuffInts; i++) {
raf.seek(raf.length() - 4);
raf.writeInt(raf.readInt());
}
raf.close();
}
},
new Tester("Mapped Read/Write") {
public void test() throws IOException {
FileChannel fc = new RandomAccessFile(
new File("temp.tmp"), "rw").getChannel();
IntBuffer ib = fc.map(
FileChannel.MapMode.READ_WRITE, 0, fc.size())
.asIntBuffer();
ib.put(0);
for(int i = 1; i < numOfUbuffInts; i++)
ib.put(ib.get(i - 1));
fc.close();
}
}
};
public static void main(String[] args) {
for(int i = 0; i < tests.length; i++)
System.out.println(tests[i].runTest());
}
} ///:~
