Jun. 2nd, 2011

today's wtf

Jun. 2nd, 2011 04:31 pm
juan_gandhi: (Default)
long min = Integer.MAX_VALUE;
long max = Integer.MIN_VALUE;


(discovered in my own code)

and when we do min = Math.min(min, newValue) where newValue = System.nanoTime() - startedNano, that's where a fuckup is happening.

We are out of the 32bit range.
juan_gandhi: (Default)
public class TimeStats extends Stats {
	private static final double MS = 0.000001;
	private long startedNano;

	public void start() {
		startedNano = System.nanoTime();
	}
	
	public void finish() {
		add(System.nanoTime() - startedNano);
	}

	public String millis(double nano) {
		return MS * nano + "ms";
	}
	
	public String toString() {
		return "min: " + millis(min) + ", max:" + millis(max) + ", avg:" + millis(average());
	}
}

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

August 2025

S M T W T F S
      12
3456789
10 11 12 13141516
17181920212223
24252627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 17th, 2025 06:25 pm
Powered by Dreamwidth Studios