Name: ssR10077 Date: 11/12/2003
###@###.###
The following test-case shows the time needed to post the set of
events to EventQueue. As events can't be processed until the run()
method returns the EventQueue steadily grows when new event is posted.
import java.awt.*;
import java.awt.event.*;
public class PostEventPerf implements Runnable {
final static int MAX_EVENTS = 1000;
final static int MAX_SERIES = 10;
public static void main(String[] args) {
EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
eq.invokeLater(new PostEventPerf());
}
public void run() {
EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
Frame frame = new Frame();
long globalStart = System.currentTimeMillis();
long globalElapsed = 0;
for (int j = 0; j < MAX_SERIES; j++) {
long startTime = System.currentTimeMillis();
for (int i = 0; i <= MAX_EVENTS; i++) {
eq.postEvent(new TestEvent(frame));
}
long elapsedTime = System.currentTimeMillis() - startTime;
globalElapsed += elapsedTime;
System.out.println("Group postEvent time:" + elapsedTime);
}
eq.postEvent(new LastEvent(frame, globalStart));
System.out.println("Global postEvent time:" + globalElapsed);
}
static class TestEvent extends AWTEvent {
TestEvent(Component obj) {
super(obj, -1);
}
}
static class LastEvent extends AWTEvent implements ActiveEvent {
long startTime;
LastEvent(Component obj, long start) {
super(obj, -1);
startTime = start;
}
public void dispatch() {
long elapsedTime = System.currentTimeMillis() - startTime;
System.out.println("Global executuion time:" + elapsedTime);
}
}
}
The test shows the following results on [1xP3-866,W2K] with 1.5.0b26
Group postEvent time:41
Group postEvent time:110
Group postEvent time:160
Group postEvent time:280
Group postEvent time:531
Group postEvent time:821
Group postEvent time:1192
Group postEvent time:1542
Group postEvent time:1733
Group postEvent time:1912
Global postEvent time:8322
Global executuion time:8523
======================================================================