summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/com/jogamp')
-rw-r--r--src/java/com/jogamp/common/os/Platform.java27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/java/com/jogamp/common/os/Platform.java b/src/java/com/jogamp/common/os/Platform.java
index 27d556c..2c1a18e 100644
--- a/src/java/com/jogamp/common/os/Platform.java
+++ b/src/java/com/jogamp/common/os/Platform.java
@@ -35,6 +35,7 @@ import java.nio.IntBuffer;
import java.nio.ShortBuffer;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.util.concurrent.TimeUnit;
import java.util.jar.JarFile;
import com.jogamp.common.nio.Buffers;
@@ -560,6 +561,30 @@ public class Platform {
*/
public static MachineDescription getMachineDescription() {
return machineDescription;
- }
+ }
+
+ //
+ // time / jitter
+ //
+
+ /**
+ * Returns the estimated sleep jitter value in nanoseconds.
+ * <p>
+ * Includes a warm-up path, allowing hotspot to optimize the code.
+ * </p>
+ */
+ public static synchronized long getCurrentSleepJitter() {
+ getCurrentSleepJitterImpl(TimeUnit.MILLISECONDS.toNanos(10), 10); // warm-up
+ return getCurrentSleepJitterImpl(TimeUnit.MILLISECONDS.toNanos(10), 10);
+ }
+ private static long getCurrentSleepJitterImpl(final long nsDuration, final int splitInLoops) {
+ final long nsPeriod = nsDuration / splitInLoops;
+ final long t0_ns = System.nanoTime();
+ for(int i=splitInLoops; i>0; i--) {
+ try { TimeUnit.NANOSECONDS.sleep(nsPeriod); } catch (InterruptedException e) { }
+ }
+ return ( ( System.nanoTime() - t0_ns ) - nsDuration ) / splitInLoops;
+ }
+
}