Создана эта простая программа, которая просто отслеживает, когда один пиксель становится белым, и записывает задержку + 100 мс. Время выполнения простой задачи на рабочем столе рабочей станции i9 с высокими характеристиками возвращает задержку в 11 мс. Что я могу сделать, чтобы достичь, возможно, задержки в 4 мс, так как я должен циклически выполнять эту задачу и постоянно запускать моделирование секундомера.
import java.awt.Color;
import java.awt.Robot;
import java.awt.AWTException;
import java.util.concurrent.TimeUnit;
public class ColorPickerDemo {
public static void main(String[] args) throws AWTException, InterruptedException {
// Data Storage Array
long[] rotateTime = new long[50];
Robot robot = new Robot();
// Queue time start
long startTime = System.nanoTime();
// Count of Array Length
int count = 0;
// Semi-Infinite Loop
while (count < 50) {
// Find the pixel color information at Position
Color colorA = robot.getPixelColor(889, 314);
//Color colorB = robot.getPixelColor(886, 319);
// Tell IF its white/tan colour
if (colorA.getRed() > 95 &&
colorA.getGreen() > 80 &&
colorA.getBlue() > 65)
{
// Record Time
long endTime = System.nanoTime();
long totalTime = endTime - startTime;
// Data storage
rotateTime[count] = totalTime;
// Print the RGB information of the pixel color
// System.out.println("Time = " + (totalTime/1000000) );
// System.out.println("RGB = " + colorA.getRed() + ", " + colorA.getGreen() + ", " + colorA.getBlue());
// Reset the timer & add count
startTime = System.nanoTime();
count ++;
Thread.sleep(100);
}
}
for (int x = 0; x < rotateTime.length; x++) {
System.out.println("index " + x + " : "+ ( rotateTime[x] / 1000000 ) );
}
}
}