本文整理汇总了C++中Timer::ElapsedTime方法的典型用法代码示例。如果您正苦于以下问题:C++ Timer::ElapsedTime方法的具体用法?C++ Timer::ElapsedTime怎么用?C++ Timer::ElapsedTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timer
的用法示例。
在下文中一共展示了Timer::ElapsedTime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv)
{
const char* addr = "tcp://192.168.1.128:3457";
if(argc <= 1) {
printf("USAGE: RealSense_ROS_Emitter tcp://SERVER_IP_ADDR:PORT\n");
printf(" Running on %s by default\n",addr);
}
File f;
if(!f.Open(addr,FILEREAD|FILEWRITE)) {
printf("Unable to open client to %s... did you run \"RealSenseClient %s\"?\n",addr,addr);
return 1;
}
//initialize ROS and publish messages
ros::init(argc, argv, "RealSense_ROS_Emitter", ros::init_options::NoSigintHandler);
ros::NodeHandle nh;
Loop loop(nh);
Timer timer;
double lastPrintTime = 0.0;
while(ros::ok()) {
if(!loop.ReadAndProcess(f)) {
printf("Abnormal termination\n");
return 1;
}
if(timer.ElapsedTime() > lastPrintTime + 1.0) {
double t = timer.ElapsedTime();
cout<<"Read rate: "<<double(loop.bytes_read)/(t-lastPrintTime)/1024/1024<<"mb/s, "<<float(loop.frames_read)/(t-lastPrintTime)<<" images/s"<<endl;
loop.bytes_read = 0;
loop.frames_read = 0;
lastPrintTime = t;
}
}
printf("Terminated due to ros::ok\n");
return 0;
}
示例2: testTimer
void testTimer(int i) {
Timer t;
sleep(i);
t.Stop();
double diff = abs(t.ElapsedTime() - i * 1000000.0);
EXPECT_GE(std::max(t.ElapsedTime() / 20, 100.0), diff);
}
示例3: main
int main()
{
Timer timer;
cout << "sleeping for 1 second and reporting:\n";
timer.Start();
sleep(1);
timer.Pause();
cout << "timed %lf secs\n", timer.ElapsedTime();
timer.Clear();
cout << "sleeping 2 times for 1 second and reporting:\n";
timer.Start();
sleep(1);
timer.Pause();
sleep(1);
timer.Start();
sleep(1);
timer.Pause();
cout << "timed %lf secs\n", timer.ElapsedTime();
return 0;
}
示例4: SolveIK
bool SolveIK(RobotIKFunction& f,
Real tolerance,int& iters,int verbose)
{
if(verbose >= 1) {
printf("SolveIK(tol=%f,iters=%d):\n",tolerance,iters);
Timer timer;
RobotIKSolver solver(f);
solver.UseJointLimits(TwoPi);
solver.solver.verbose = verbose;
if(solver.Solve(tolerance,iters)) {
printf(" Succeeded! %f seconds\n", timer.ElapsedTime());
if(verbose >= 2) solver.PrintStats();
return true;
}
else {
printf(" Failed... %f seconds\n", timer.ElapsedTime());
if(verbose >= 2) solver.PrintStats();
return false;
}
}
else {
RobotIKSolver solver(f);
solver.UseJointLimits(TwoPi);
solver.solver.verbose = verbose;
return solver.Solve(tolerance,iters);
}
}
示例5: ROSWaitForUpdate
bool ROSWaitForUpdate(const char* topic,double timeout)
{
if(gSubscribers.count(topic) == 0) return false;
ROSSubscriberBase* s = gSubscribers[topic];
int oldNumMessages = s->numMessages;
Timer timer;
while(timer.ElapsedTime() < timeout) {
ros::spinOnce();
ros::Duration(Min(timeout-timer.ElapsedTime(),0.001)).sleep();
if(s->numMessages > oldNumMessages) return true;
}
return false;
}
示例6: OnMessage
virtual bool OnMessage(AnyCollection& message) {
cout<<message<<endl;
double t = timer.ElapsedTime();
printf("Time between messages: %g\n",t-lastTime);
lastTime = t;
return true;
}
示例7: InitCollisions
void RigidObject::InitCollisions()
{
Timer timer;
geometry->InitCollisionData();
double t = timer.ElapsedTime();
if(t > 0.2)
printf("Initialized rigid object %s collision data structures in time %gs\n",geomFile.c_str(),t);
}
示例8: TimeOptimizeTest1DParabolic
void TimeOptimizeTest1DParabolic()
{
Vector vmin(1,-1.0),vmax(1,1.0);
Vector amin(1,-1.0),amax(1,1.0);
//try the path from -1 to 1
int ns [] = {2,4,8,16,32,64,128,256,512,1024};
for(int i=0;i<10;i++) {
int numSegments = ns[i];
vector<Real> divs(numSegments+1);
vector<Vector> vmins(numSegments),vmaxs(numSegments);
vector<Vector> amins(numSegments),amaxs(numSegments);
vector<Vector> vs(numSegments+1);
for(int j=0;j<=numSegments;j++) {
divs[j] = Real(j)/Real(numSegments);
vs[j] = Vector(1,8.0*Abs(divs[j]-0.5));
if(j > 0) {
vmins[j-1] = vs[j-1];
vmaxs[j-1] = vs[j];
if(divs[j] < 0.5)
Swap(vmins[j-1],vmaxs[j-1]);
amins[j-1] = Vector(1,8.0*Sign(divs[j-1]-0.5));
amaxs[j-1] = Vector(1,8.0*Sign(divs[j-1]-0.5));
}
}
Timer timer;
TimeScaling timeScaling;
//timeScaling.ConditionMinTime(divs,vs,vmins,vmaxs,amins,amaxs);
bool res=timeScaling.SolveMinTimeArcLength(vmin,vmax,amin,amax,divs,vs,0.0,0.0);
double time=timer.ElapsedTime();
printf("Num segments: %d\n",numSegments);
printf("Result: %d\n",res);
if(res) {
printf("End time: %g\n",timeScaling.times.back());
printf("Solution time: %g s\n",time);
/*
for(size_t j=0;j<timeScaling.ds.size();j++)
Assert(vmin[0] <= timeScaling.ds[j]*vs[j][0] && timeScaling.ds[j]*vs[j][0] <= vmax[0]);
*/
}
#if PRINT_TIME_SCALING
if(i+1==10) {
cout<<"time,s,ds,val,vmin,vmax,amin,amax,dy,ddy"<<endl;
for(size_t i=0;i<timeScaling.times.size();i++) {
cout<<timeScaling.times[i]<<","<<timeScaling.params[i]<<","<<timeScaling.ds[i]<<","<<4.0*Pow(timeScaling.params[i]-0.5,2.0)*Sign(timeScaling.params[i]-0.5);
if(i<vmins.size()) {
Real dp=8.0*Abs(timeScaling.params[i]-0.5);
Real ddp=8.0*Sign(timeScaling.params[i]-0.5);
cout<<","<<vmins[i][0]<<","<<vmaxs[i][0]<<","<<amins[i][0]<<","<<amaxs[i][0];
cout<<","<<timeScaling.ds[i]*dp<<","<<timeScaling.TimeToParamAccel(i,timeScaling.times[i])*dp+Sqr(timeScaling.ds[i])*ddp<<endl;
}
else cout<<endl;
}
}
#endif // PRINT_TIME_SCALING
}
}
示例9: CalibrateLatency
void SafeTrajClient::CalibrateLatency(int iters)
{
if(virtualController) return;
printf("SafeTrajClient: Calibrating latency... \n");
Timer timer;
for (int i=0;i<iters;i++)
this->t.Echo("");
this->latency = timer.ElapsedTime()/iters;
printf(" result %g\n",this->latency);
}
示例10: InitCollisions
void CollisionPointCloud::InitCollisions()
{
Assert(points.size() > 0);
Timer timer;
bblocal.minimize();
for(size_t i=0;i<points.size();i++)
bblocal.expand(points[i]);
//set up the grid
Real res = gridResolution;
if(gridResolution <= 0) {
Vector3 dims = bblocal.bmax-bblocal.bmin;
Real maxdim = Max(dims.x,dims.y,dims.z);
Real mindim = Min(dims.x,dims.y,dims.z);
//default grid size: assume points are evenly distributed on a 2D manifold
//in space, try to get 50 points per grid cell
Real vol = dims.x*dims.y*dims.z;
//h^2 * n = vol
int ptsPerCell = 50;
Real h = Pow(vol / points.size() * ptsPerCell, 1.0/2.0);
if(h > mindim) {
//TODO: handle relatively flat point clouds
}
res = h;
}
grid.h.set(res);
for(size_t i=0;i<points.size();i++) {
Vector p(3,points[i]);
GridSubdivision::Index ind;
grid.PointToIndex(p,ind);
grid.Insert(ind,&points[i]);
}
printf("CollisionPointCloud::InitCollisions: %d points, res %g, time %gs\n",points.size(),res,timer.ElapsedTime());
//print stats
int nmax = 0;
for(GridSubdivision::HashTable::const_iterator i=grid.buckets.begin();i!=grid.buckets.end();i++)
nmax = Max(nmax,(int)i->second.size());
printf(" %d nonempty grid buckets, max size %d, avg %g\n",grid.buckets.size(),nmax,Real(points.size())/grid.buckets.size());
timer.Reset();
//initialize the octree, 10 points per cell
octree = new OctreePointSet(bblocal,10);
for(size_t i=0;i<points.size();i++)
octree->Add(points[i],(int)i);
printf(" octree initialized in time %gs, %d nodes\n",timer.ElapsedTime(),octree->Size());
/*
//TEST: method 2. Turns out to be much slower
timer.Reset();
octree = new OctreePointSet(bblocal,points.size());
octree->SplitToResolution(res);
for(size_t i=0;i<points.size();i++)
octree->Add(points[i],(int)i);
octree->Collapse(10);
printf(" octree 2 initialized in time %gs, %d nodes\n",timer.ElapsedTime(),octree->Size());
*/
}
示例11: main
int main(int argc, const char *argv[])
{
string input_file("words.sorted");
leveldb::DB* db;
leveldb::Options options;
options.create_if_missing = true;
string idx_name = input_file + ".leveldb";
leveldb::Status status = leveldb::DB::Open(options, idx_name.c_str(), &db);
assert(status.ok());
vector<string> tokens;
loadTokens(input_file.c_str(), tokens);
char v[256];
for (int i = 0; i < tokens.size(); ++i) {
string token = tokens[i];
sprintf(v, "%d", (int)token.size());
string value(v);
db->Put(leveldb::WriteOptions(), token, value);
}
int count = tokens.size();
Timer t;
string value;
for (int i = 0; i < count; ++i) {
string token = tokens[i];
db->Get(leveldb::ReadOptions(), token, &value);
//int key_len = 0;
//sscanf(value.data(), "%d", &key_len);
//cout << key_len << " " << token << endl;
//assert(key_len == token.size());
}
t.Stop();
cout << "cpu time(s):" << t.ElapsedTimeCPU() / 1000000
<< " avg(us):" << t.ElapsedTimeCPU()/count << endl
<< "wall time(s):" << t.ElapsedTime() / 1000000
<< " avg(us):" << t.ElapsedTime()/count << endl;
delete db;
return 0;
}
示例12: Handle_Idle
virtual void Handle_Idle() {
if(simulate) {
Timer timer;
string res=uis[currentUI]->UpdateEvent();
sim.Advance(dt);
Refresh();
SleepIdleCallback(int(Max(0.0,dt-timer.ElapsedTime())*1000.0));
}
WorldViewProgram::Handle_Idle();
}
示例13: WaitForMessage
bool Service::WaitForMessage(AnyCollection& message,double timeout)
{
if(!worker) {
fprintf(stderr,"%s::WaitForMessage(): Not connected\n",Name());
return false;
}
Timer timer;
while(timer.ElapsedTime() < timeout) {
if(!worker->initialized) {
fprintf(stderr,"%s::WaitForMessage(): Abnormal disconnection\n",Name());
return false;
}
//read new messages
if(worker->UnreadCount() > 0) {
if(onlyProcessNewest) {
string str = worker->Newest();
stringstream ss(str);
AnyCollection msg;
if(!msg.read(ss)) {
fprintf(stderr,"%s::WaitForMessage(): Got an improperly formatted string\n",Name());
cout<<"String = \""<<str<<"\""<<endl;
return false;
}
if(!OnMessage(msg)) {
fprintf(stderr,"%s::WaitForMessage(): OnMessage returned false\n",Name());
return false;
}
message = msg;
return true;
}
else {
vector<string> msgs = worker->New();
for(size_t i=0;i<msgs.size();i++) {
stringstream ss(msgs[i]);
AnyCollection msg;
if(!msg.read(ss)) {
fprintf(stderr,"%s::WaitForMessage(): Got an improperly formatted string\n",Name());
return false;
}
if(!OnMessage(msg)) {
fprintf(stderr,"%s::WaitForMessage(): OnMessage returned false\n",Name());
return false;
}
}
message = msgs[0];
return true;
}
ThreadSleep(SSPP_MESSAGE_WAIT_TIME);
}
}
return false;
}
示例14: mkl_spmv
/* SpMV kernel implemented with Intel MKL */
void mkl_spmv(spx_index_t *rowptr, spx_index_t *colind, spx_value_t *values,
spx_index_t nrows, spx_index_t ncols, spx_index_t nnz,
spx_value_t *x, spx_value_t *y,
spx_value_t ALPHA, spx_value_t BETA)
{
/* 1. Matrix loading phase */
MKL_INT *pointerB, *pointerE;
char transa;
char matdescra[6];
transa = 'n';
matdescra[0] = 'g';
matdescra[1] = '-';
matdescra[2] = '-';
matdescra[3] = 'c';
pointerB = (MKL_INT *) malloc(sizeof(MKL_INT) * nrows);
pointerE = (MKL_INT *) malloc(sizeof(MKL_INT) * nrows);
for (int i = 0; i < nrows; i++) {
pointerB[i] = rowptr[i];
pointerE[i] = rowptr[i+1];
}
/* 2. SpMV benchmarking phase */
vector<double> mt(OUTER_LOOPS);
for (size_t i = 0; i < OUTER_LOOPS; i++) {
t.Clear();
t.Start();
for (size_t j = 0; j < LOOPS; j++) {
mkl_dcsrmv(&transa, &nrows, &ncols, &ALPHA, matdescra, values,
colind, pointerB, pointerE, x, &BETA, y);
}
t.Pause();
mt[i] = t.ElapsedTime();
}
sort(mt.begin(), mt.end());
double mt_median =
(OUTER_LOOPS % 2) ? mt[((OUTER_LOOPS+1)/2)-1]
: ((mt[OUTER_LOOPS/2-1] + mt[OUTER_LOOPS/2])/2);
double flops = (double)(LOOPS*nnz*2)/((double)1000*1000*mt_median);
cout << "m: " << MATRIX
<< " mt(median): " << mt_median
<< " flops: " << flops << endl;
/* 3. Cleanup */
free(pointerB);
free(pointerE);
}
示例15: OnIdle
virtual bool OnIdle() {
bool res=SimGUIBackend::OnIdle();
if(simulate) {
Timer timer;
string res=ui->UpdateEvent();
sim.Advance(dt);
SendRefresh();
SendPauseIdle(int(Max(0.0,dt-timer.ElapsedTime())*1000.0));
return true;
}
return res;
}