Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.util.Log;
- public class Timer {
- int _counter = 0;
- String _name;
- int _numframes;
- boolean started = false;
- long _starttime;
- double _cumulative = 0;
- double _lastElapsed = 0;
- double _lastAverage = 0;
- double _lastWorst = 0;
- public Timer(String name, int framecount){
- _name = name;
- _numframes = framecount;
- }
- public void start(){
- _starttime = System.nanoTime();
- started = true;
- }
- public void end(){
- if(!started) return;
- started = false;
- long endtime = System.nanoTime();
- _lastElapsed = (double)(endtime -_starttime)/ 1.0E9;
- _lastWorst = Math.max(_lastWorst, _lastElapsed);
- _cumulative += _lastElapsed;
- if(++_counter >= _numframes){
- _lastAverage = _cumulative/_numframes;
- Log.d("Timer", _name + ": " +
- String.format("%.2f",_lastAverage*1000) +
- "ms (worst " +
- String.format("%.2f",_lastWorst*1000) +
- "ms)"
- );
- _counter = 0;
- _cumulative =0;
- _lastWorst = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement