Pattern: How to measure UI response time? [message #520683] |
Sun, 14 March 2010 09:19 |
Ralf Ebert Messages: 168 Registered: July 2009 |
Senior Member |
|
|
Hi,
I was just wondering: How would one test that something is executed in a background thread
and the UI stays responsive? I did it the following way, is there a better solution for this?
StopWatch watch = new StopWatch("UI response time");
someButton.click();
watch.assertDurationLessThanMs(100);
--------------
public class StopWatch {
private final String name;
private final long startTime;
public StopWatch(String name) {
this.name = name;
this.startTime = System.currentTimeMillis();
}
public void assertDurationLessThanMs(long maxResponseTime) {
long duration = getDuration();
if (duration > maxResponseTime) {
throw new RuntimeException(name + " was " + duration + " ms, > than " + maxResponseTime
+ " ms");
}
}
public long getDuration() {
return System.currentTimeMillis() - startTime;
}
}
Greetings,
Ralf
--
http://www.ralfebert.de/blog/eclipsercp/
|
|
|
Powered by
FUDForum. Page generated in 0.03504 seconds