summaryrefslogtreecommitdiffstats
path: root/src/jake2/sys/HighPrecisionTimer.java
blob: a8a0201a174e1944aa067a2ce344235c9857dd08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
 * HighPrecisionTimer.java
 * Copyright (C) 2005
 * 
 * $Id: HighPrecisionTimer.java,v 1.1 2005-07-01 14:11:00 hzi Exp $
 */
package jake2.sys;

import sun.misc.Perf;




class HighPrecisionTimer extends Timer {

	private Perf perf = Perf.getPerf();
	private double f = 1000.0 / perf.highResFrequency();
	private long base;
	
	HighPrecisionTimer() {
		base = perf.highResCounter();
	}
	
	public long currentTimeMillis() {
		long time = perf.highResCounter();
		long delta = time - base;
		if (delta < 0) {
			delta += Long.MAX_VALUE + 1;
		}
		return (long)(delta * f);
	}
}