Created
September 28, 2013 13:34
-
-
Save heyfluke/6742141 to your computer and use it in GitHub Desktop.
record touch-event times and show reports.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// start TouchProfiler.h | |
#ifndef __MySketchPad__TouchProfiler__ | |
#define __MySketchPad__TouchProfiler__ | |
#include <deque> | |
using namespace std; | |
class TouchProfiler | |
{ | |
public: | |
TouchProfiler(); | |
~TouchProfiler(); | |
void init(); | |
void report(); | |
void addPoint(); | |
void addEnd(); | |
int pointCount(); | |
private: | |
deque<double> points; | |
deque<double> avgrates; | |
}; | |
#endif /* defined(__MySketchPad__TouchProfiler__) */ | |
/// end TouchProfiler | |
/// start TouchProfiler.mm | |
#include "TouchProfiler.h" | |
TouchProfiler::TouchProfiler() | |
{ | |
// | |
} | |
TouchProfiler::~TouchProfiler() | |
{ | |
points.clear(); | |
} | |
void TouchProfiler::init() | |
{ | |
points.clear(); | |
avgrates.clear(); | |
} | |
void TouchProfiler::report() | |
{ | |
double last = 0; | |
double sum = 0; | |
double mindiff = 0xfff; | |
double maxdiff = 0.0; | |
for (int i=0; i<points.size(); ++i) { | |
double cur = points[i]; | |
if (last - 0.0 > 0.0001) { | |
double curdiff = cur-last; | |
printf(" >>> current diff: %lf\n", curdiff); | |
sum += curdiff; | |
if (curdiff < mindiff) { | |
mindiff = curdiff; | |
} | |
if (curdiff > maxdiff) { | |
maxdiff = curdiff; | |
} | |
} | |
last = cur; | |
} | |
if (points.size() > 1) { | |
double avg = sum/(points.size()-1); | |
printf(" >>> sum:%lf, agv:%lf, max:%lf, min:%lf\n", sum, avg, maxdiff, mindiff); | |
} | |
points.clear(); | |
} | |
void TouchProfiler::addPoint() | |
{ | |
double currentTime = CACurrentMediaTime(); | |
points.push_back(currentTime); | |
} | |
void TouchProfiler::addEnd() | |
{ | |
report(); | |
} | |
int TouchProfiler::pointCount() | |
{ | |
return points.size(); | |
} | |
/// end TouchProfiler.mm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment