Doh,
This time with the patches, test code, and CPU usage stats attached
Regard
Mike
>________________________________
>From: Alan Bateman <alan.bate...@oracle.com>
>To: mike.ske...@talk21.com
>Cc: Core-Libs-Dev <core-libs-dev@openjdk.java.net>
>Sent: Monday, 10 October 2011, 0:15
>Subject: Re: Patch to Throwable and StackTraceElement (reduced CPU usage)
>
>mike.ske...@talk21.com wrote:
>> :
>>
>>
>> I include the patch, a micro-benchmark and the results of the
>> micro-benchmark which show an improvement of 80% throughput (ie it is almost
>> twice as fast)
>>
>Mike - I don't think there is a patch attached to your mail.
>
>
>
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package compare;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
*
* @author mike
*/
public class TestThrow {
public static void main(String[] args) throws InterruptedException {
try {
generateThrow1(5);
} catch (Throwable t) {
int count = 100;
StringWriter sw = new StringWriter(20000);
PrintWriter pw = new PrintWriter(sw);
System.out.println(sw);
for (int j = 0; j < 100; j++) {
long total = 0;
for (int i = 0; i < count; i++) {
sw.getBuffer().setLength(0);
long start = System.nanoTime();
t.printStackTrace(pw);
long end = System.nanoTime();
total += end - start;
}
System.out.println((total / count));
}
}
}
private static void generateThrow1(int depth) {
generateThrow2(depth);
}
private static void generateThrow2(int depth) {
generateThrow3(depth);
}
private static void generateThrow3(int depth) {
generateThrow4(depth);
}
private static void generateThrow4(int depth) {
generateThrow5(depth);
}
private static void generateThrow5(int depth) {
if (depth == 0) {
throw new RuntimeException("some text ..." + depth);
} else {
try {
generateThrow1(depth - 1);
} catch (RuntimeException x) {
throw new RuntimeException("some text ..." + depth, x);
}
}
}
}