The code you posted really hasn't helped (it's not compilable, it has a reference to a class that you didn't post the code to, and it's not demonstrating your problem). However, using the shell of what you posted, I did the following:
public class Test {
public static void main(final String[] args) {
new Test().doStuff();
}
private void doStuff() {
long start;
long end;
while (true) {
start = System.nanoTime();
Point point = MouseInfo.getPointerInfo().getLocation();
end = System.nanoTime();
System.out.println("Time taken: " + (end - start));
}
}
}
This gave me output as follows:
Time taken: 183564075
Time taken: 24498
Time taken: 16448
Time taken: 16448
Time taken: 16798
Time taken: 16098
Time taken: 16798
Time taken: 21697
Time taken: 16448
Time taken: 17498
Time taken: 26597
So while there is a large value for the very first run, this can easily be explained as a ramp up issue, if you are running this in a tight loop, it quickly drops to a few ms.
If you don't like that, you could always track the mouse yourself, and store the last position using a MouseMotiontListener or a MouseMotitonAdapter
public class Test {
public static void main(final String[] args) {
new Test().doStuff();
}
private void doStuff() {
long start;
long end;
MouseTracker tracker = new MouseTracker();
while (true) {
start = System.nanoTime();
Point point = tracker.getLocation();
end = System.nanoTime();
System.out.println("Time taken: " + (end - start));
}
}
class MouseTracker extends MouseMotionAdapter {
private Point location;
@Override
public void mouseMoved(final MouseEvent e) {
location = e.getLocationOnScreen();
}
public Point getLocation() {
return location;
}
}
}
Using that gives much lower values (even for ramp-up)
Time taken: 3150
Time taken: 350
Time taken: 0
Time taken: 0
Time taken: 0
Time taken: 0
Time taken: 350
Time taken: 0
Time taken: 350