public class Program {
public static void testSpeed(int ms) {
long currentTime = System.currentTimeMillis();
for (int i = 0; i < 1000; i++) {
try {
Thread.sleep(ms);
} catch (InterruptedException e) {
Thread.currentThread().interrupt(); // restore interrupt status
System.out.println("Sleep interrupted at iteration " + i);
return;
}
}
System.out.println("Executed in " + (System.currentTimeMillis() - currentTime) + " ms");
}
public static void main(String[] args) {
testSpeed(1);
}
}
/*
run:
Executed in 1090 ms
*/