当前位置: 首页>>代码示例>>C++>>正文


C++ duration::count方法代码示例

本文整理汇总了C++中std::chrono::duration::count方法的典型用法代码示例。如果您正苦于以下问题:C++ duration::count方法的具体用法?C++ duration::count怎么用?C++ duration::count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::chrono::duration的用法示例。


在下文中一共展示了duration::count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: timerCallBack

void QVirtualClock::timerCallBack( std::chrono::duration<double>& elapsed_sleep_seconds )
{
    UInt32 elapsed_sec = static_cast<UInt32>(elapsed_sleep_seconds.count( ));
    
    if (elapsed_sec < 1)
    {
        return; //this should never happen because boost::sleep guarantees it.
    }
    
    if (!m_update_time_invoked)
    {
        //This can happen if pdu reception is not yet started, or if for some reason pdus have not
        // been received from one timerCallBack invocation to another, or if pdus have stopped completely.
        //The solution is to keep virtual time alive
        UInt32 elapsed_msec_fraction   = (static_cast<UInt32>(elapsed_sleep_seconds.count( ) *1000000)) % 1000000;
        UInt64 virtual_time_correction = (static_cast<UInt64>(elapsed_sec) << 32 | elapsed_msec_fraction);
        
        m_virtual_time+=virtual_time_correction;
    }

    for (UInt32 i = 0; i < elapsed_sec; i++)
    {
        ++m_total_elapsed_seconds;

        propagateTimePulseEventToRegistered();
    }

    m_update_time_invoked = false;
}
开发者ID:benelgiac,项目名称:PoC,代码行数:29,代码来源:QVirtualClock.cpp

示例2: game_over

 //! Increments statistics for lose event.
 //! \param duration Duration of that game play.
 void game_over(const std::chrono::duration<long long>& duration)
 {
     ++m_stats[StatTypes::GAME_LOSES];
     m_stats[StatTypes::FASTEST_LOSE] = m_stats[StatTypes::FASTEST_LOSE] != 0 ? std::min(duration.count(), m_stats[StatTypes::FASTEST_LOSE]) : duration.count();
     m_stats[StatTypes::SLOWEST_LOSE] = std::max(duration.count(), m_stats[StatTypes::SLOWEST_LOSE]);
     m_stats[StatTypes::TOTAL_TIME_PLAYED] += duration.count();
 }
开发者ID:Zereges,项目名称:2048RP,代码行数:9,代码来源:stats.hpp

示例3: won

 //! Increments statistics for win event.
 //! \param duration Duration of that game play.
 void won(const std::chrono::duration<long long>& duration)
 {
     ++m_stats[StatTypes::GAME_WINS];
     m_stats[StatTypes::FASTEST_WIN] = m_stats[StatTypes::FASTEST_WIN] != 0 ? std::min(duration.count(), m_stats[StatTypes::FASTEST_WIN]) : duration.count();
     m_stats[StatTypes::SLOWEST_WIN] = std::max(duration.count(), m_stats[StatTypes::SLOWEST_WIN]);
     m_stats[StatTypes::TOTAL_TIME_PLAYED] += duration.count();
 }
开发者ID:Zereges,项目名称:2048RP,代码行数:9,代码来源:stats.hpp

示例4: bench

void bench() {
    
    warmup();
    const int itrNum = 50;
    int size = 1024 * 1024 * 1024;
    char* s1 = (char*) malloc(sizeof (char) * size);
    char* s2 = (char*) malloc(sizeof (char) * size);
    for (int i = 0; i < size; i++)
        s1[i] = ('a' + i % 26);
    
    int blocksizes[] = {8, 16, 128, 512, 1024, 
                        4096, 1024 * 1024, 1024 * 1024 * 4, 1024 * 1024 * 8, 
                        73, 113, 1024 * 1024 + 97};
   
    {
        
        for (int i = 0; i < sizeof(blocksizes)/sizeof(int); i++) {
            
            const auto t1 = std::chrono::high_resolution_clock::now();
            int num = size / blocksizes[i];
            
            for (int itr = 0; itr < itrNum; itr++) {
                for (int j = 0; j < num; j++) {
                    memcpy((s2 + blocksizes[i] * j), (s1 + blocksizes[i] * j), blocksizes[i]);
                }
            }

            const auto t2 = std::chrono::high_resolution_clock::now();
            const std::chrono::duration<double> td = t2 - t1;
            double result = ((double)itrNum*(size/(1024*1024))) / td.count();
            printf("glibc,memcpy:\tblockSize=%d, \t\tresult = %10.6f MB/s,\ttime = %10.6f s\n", blocksizes[i], result, td.count()); 
        }
    }

    {
        
        for (int i = 0; i < sizeof (blocksizes) / sizeof (int); i++) {

            const auto t1 = std::chrono::high_resolution_clock::now();
            int num = size / blocksizes[i];

            for (int itr = 0; itr < itrNum; itr++) {
                for (int j = 0; j < num; j++) {
                    _i_memcpy_256_unaligned((s2 + blocksizes[i] * j), (s1 + blocksizes[i] * j), blocksizes[i]);
                }
            }

            const auto t2 = std::chrono::high_resolution_clock::now();
            const std::chrono::duration<double> td = t2 - t1;
            double result = ((double) itrNum * (size / (1024 * 1024))) / td.count();
            printf("our poc memcpy:\tblockSize=%d,  \t\tresult = %10.6f MB/s,\ttime = %10.6f s\n", blocksizes[i], result, td.count());
        }         
    }
}
开发者ID:kexianda,项目名称:misc,代码行数:54,代码来源:driver.cpp

示例5: defined

void
SinkClient::update(Observable<std::shared_ptr<VideoFrame>>* /*obs*/,
                   const std::shared_ptr<VideoFrame>& frame_p)
{
    auto& f = *frame_p;

#ifdef DEBUG_FPS
    auto currentTime = std::chrono::system_clock::now();
    const std::chrono::duration<double> seconds = currentTime - lastFrameDebug_;
    ++frameCount_;
    if (seconds.count() > 1) {
        std::ostringstream fps;
        fps << frameCount_ / seconds.count();
        // Send the framerate in smartInfo
        Smartools::getInstance().setFrameRate(id_, fps.str());
        frameCount_ = 0;
        lastFrameDebug_ = currentTime;
    }
#endif

#if HAVE_SHM
    // Send the resolution in smartInfo
    Smartools::getInstance().setResolution(id_, f.width(), f.height());
    shm_->renderFrame(f);
#endif

    if (target_.pull) {
        VideoFrame dst;
        VideoScaler scaler;
        const int width = f.width();
        const int height = f.height();
#if (defined(__ANDROID__) || defined(__APPLE__))
        const int format = VIDEO_PIXFMT_RGBA;
#else
        const int format = VIDEO_PIXFMT_BGRA;
#endif
        const auto bytes = videoFrameSize(format, width, height);

        if (bytes > 0) {
            if (auto buffer_ptr = target_.pull(bytes)) {
                buffer_ptr->format = libav_utils::libav_pixel_format(format);
                buffer_ptr->width = width;
                buffer_ptr->height = height;
                dst.setFromMemory(buffer_ptr->ptr, format, width, height);
                scaler_->scale(f, dst);
                target_.push(std::move(buffer_ptr));
            }
        }
    }
}
开发者ID:asadsalman,项目名称:ring-daemon,代码行数:50,代码来源:sinkclient.cpp

示例6: retry_for

    inline bool retry_for(
        const std::chrono::duration<Rep, Period>& total_time,
        const std::chrono::duration<Rep, Period>& time_step,
        std::function<bool (void)> retried_func) {
      assert(time_step.count()!=0);
      assert(total_time.count() >= time_step.count());

      size_t iterations = total_time.count() / time_step.count();
      for(size_t p=0; p <iterations; p++) {
        if(retried_func()) { return true; }
        std::this_thread::sleep_for(time_step);
      }
      return false;
    }
开发者ID:daminetreg,项目名称:lib-cpp-pre,代码行数:14,代码来源:retry_for.hpp

示例7: while

FutureReturnCode
spin_node_until_future_complete(
  rclcpp::executor::Executor & executor, rclcpp::node::Node::SharedPtr node_ptr,
  std::shared_future<ResponseT> & future,
  std::chrono::duration<int64_t, TimeT> timeout = std::chrono::duration<int64_t, TimeT>(-1))
{
  // TODO(wjwwood): does not work recursively right, can't call spin_node_until_future_complete
  // inside a callback executed by an executor.

  // Check the future before entering the while loop.
  // If the future is already complete, don't try to spin.
  std::future_status status = future.wait_for(std::chrono::seconds(0));

  auto start_time = std::chrono::system_clock::now();

  while (status != std::future_status::ready && rclcpp::utilities::ok()) {
    executor.spin_node_once(node_ptr, timeout);
    if (timeout.count() >= 0) {
      if (start_time + timeout < std::chrono::system_clock::now()) {
        return TIMEOUT;
      }
    }
    status = future.wait_for(std::chrono::seconds(0));
  }

  // If the future completed, and we weren't interrupted by ctrl-C, return the response
  if (status == std::future_status::ready) {
    return FutureReturnCode::SUCCESS;
  }
  return FutureReturnCode::INTERRUPTED;
}
开发者ID:allenh1,项目名称:rclcpp,代码行数:31,代码来源:executors.hpp

示例8: frameRenderingQueued

// This gets called while rendering frame data is loading into GPU
// Good time to update measurements and physics before rendering next frame!
bool App::frameRenderingQueued(const Ogre::FrameEvent& evt) 
{
	//calculate delay and show
	delay = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - last_request);
	frames_per_second(delay.count());

	if (mShutdown) return false;

	if(mRift)
	{
		if ( mRift->update( evt.timeSinceLastFrame ) )
		{
			mScene->setRiftPose( mRift->getOrientation(), mRift->getPosition() );
		} else {
			delete mRift;
			mRift = NULL;
		}
	}

	//update the standard input devices
	mKeyboard->capture();
	mMouse->capture();

	//call updates on scene elements
	mScene->update( evt.timeSinceLastFrame );

	//get now time
	last_request = std::chrono::system_clock::now();

	//exit if key ESCAPE pressed 
	if(mKeyboard->isKeyDown(OIS::KC_ESCAPE)) 
		return false;

	return true; 
}
开发者ID:fakkoweb,项目名称:OgreOculusApp,代码行数:37,代码来源:App.cpp

示例9: wait_for_impl

	_cv_status wait_for(std::unique_lock<std::mutex>& lock, const std::chrono::duration<Rep, Period>& rel_time)
	{
		if (rel_time.count() < 0)
		{
			return std::cv_status::timeout;
		}

		duration dur = std::chrono::duration_cast<duration>(rel_time);
		if (dur.count() == 0 && rel_time.count() != 0)
		{
			// don't do zero wait if non-zero wait was requested
			dur = duration(1);
		}

		return wait_for_impl(lock, dur);
	}
开发者ID:Aidanboneham,项目名称:wgtf,代码行数:16,代码来源:wg_condition_variable.hpp

示例10: main

int main(int argc, char* argv[]){
    nome_programa = argv[0];
    if(argc == 1) uso();
    else configura(argc, argv);

    /*-------------------
      Solovay-Strassen
    -------------------*/
    if(SS && !MR && !BPSW){
        if(!quiet){
            std::cout << "Solovay-Strassen -- Contagem de Tempo: ";
            tempo ? std::cout << "ativada.\n" : std::cout << "desativada.\n";
        }

        while(std::cin >> n >> k){
            tempo_decorrido = std::chrono::steady_clock::duration::zero();
            inicio = std::chrono::steady_clock::now();
            teste = solovay_strassen(n, k);
            fim = std::chrono::steady_clock::now();
            if(teste) std::cout << n << " e provavelmente primo.";
            else std::cout << n << " e composto.";
            if(tempo){
                tempo_decorrido = std::chrono::duration_cast<std::chrono::duration<double>>(fim - inicio);
                std::cout << " Tempo de execucao: " << tempo_decorrido.count();
            }
            std::cout << std::endl;
        }
    }

    /*----------------
        Miller-Rabin
    ----------------*/
    else if(!SS && MR && !BPSW){
开发者ID:ildosrel,项目名称:Projeto-Final,代码行数:33,代码来源:Prob.cpp

示例11: tick

void CocoDeviceWrapper::tick()
{
	if(video)
	{
		glClearColor(0.0, 0.0, 0.0, 1.0);
		glClear(GL_COLOR_BUFFER_BIT);
		glwrap->SwapBuffers();
		return;
	}
	static size_t count = 0;
	static double total = 0.0;
	static std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
    static std::chrono::steady_clock::time_point now, last_tick = std::chrono::steady_clock::now(), last_draw = std::chrono::steady_clock::now();
    static std::chrono::duration<double, std::milli> tick_dif = std::chrono::duration<double, std::milli>::zero();
    static std::chrono::duration<double, std::milli> draw_dif = std::chrono::duration<double, std::milli>::zero();

    // Mark time and calc difference since last call
    now = std::chrono::steady_clock::steady_clock::now();
    draw_dif = now - last_draw;
    tick_dif = now - last_tick;

    // If the time ellapsed is grater than 16ms we flush OpenGL trying to achieve 60 fps.
    if((draw_dif + tick_dif).count() > 16.0)
    {
        last_draw = now;
        if(glwrap)
        {
        	double td = std::chrono::duration_cast<std::chrono::duration<double, std::milli>>(now - start).count();
        	#ifdef __XMLHTTPREQUEST_HPP__
        	XMLHttpRequest::tick();
        	#endif
        	engine->run(td);
        	glwrap->SwapBuffers();
        	if(count++ == 30)
        	{
        		count = 1;
        		total = draw_dif.count();
        	} else total += draw_dif.count();
        }

        now = std::chrono::steady_clock::steady_clock::now();
    }
    last_tick = now;
}
开发者ID:Czou,项目名称:Coconut2D,代码行数:44,代码来源:CocoDeviceWrapper.cpp

示例12: CameraCallback

void CameraCallback(CCamera* cam, const void* buffer, int buffer_length)
{
	// check ellapsed time and increment fps as long as the the frame is received withthin the specified interval 
	t2 = std::chrono::high_resolution_clock::now();
        time_span = std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1);    	
	if(time_span.count() < 10 ){
		fps += 1;
	}else{
		printf("fps: %f\n", fps/time_span.count());
		startMilliSecondTimer();
		fps = 0;	
	}
	//printf("Ellapsed time: %.3f received %d bytes of data\n", time_span.count, buffer_length);
	cv::Mat myuv(HEIGHT + HEIGHT/2, WIDTH, CV_8UC1, (unsigned char*)buffer);
	cv::Mat mrgb(HEIGHT, WIDTH, CV_8UC4, dest);
	cv::cvtColor(myuv, mrgb, CV_YUV2RGBA_NV21); 
	//cv::imshow("video", mrgb);
	//cv::waitKey(1);
}
开发者ID:Roboy,项目名称:legs,代码行数:19,代码来源:picam.cpp

示例13: main

int main(int argc, char * const argv[]) {
  const int blockSize = 64;
  const int numInputChannels = 2;
  const int numOutputChannels = 2;
  const float sampleRate = 22050.0f;
  
  // pass directory and filename of the patch to load
  PdContext *context = zg_context_new(numInputChannels, numOutputChannels, blockSize, sampleRate,
      callbackFunction, NULL);
  
  // create a graph from a file
  
  PdGraph *graph = zg_context_new_graph_from_file(context, "/Users/mhroth/workspace/ZenGarden/demo/", "echolon_test0.pd");
  if (graph == NULL) {
    zg_context_delete(context);
    return 1;
  }
  
  /*
  // create a graph manually
  PdGraph *graph = zg_context_new_empty_graph(context);
  ZGObject *objOsc = zg_graph_add_new_object(graph, "osc~ 440", 0.0f, 0.0f);
  ZGObject *objDac = zg_graph_add_new_object(graph, "dac~", 0.0f, 0.0f);
  zg_graph_add_connection(graph, objOsc, 0, objDac, 0);
  zg_graph_add_connection(graph, objOsc, 0, objDac, 1);
  */
  // attach the graph
  zg_graph_attach(graph);
  
  float *inputBuffers = (float *) calloc(numInputChannels * blockSize, sizeof(float));
  float *outputBuffers = (float *) calloc(numOutputChannels * blockSize, sizeof(float));

  const auto start = std::chrono::high_resolution_clock::now();

  for (int i = 0; i < NUM_ITERATIONS; i++) {
  //while (1) {
    zg_context_process(context, inputBuffers, outputBuffers);
  }

  const auto end = std::chrono::high_resolution_clock::now();
  const std::chrono::duration<double> elapsedTimeSeconds = (end - start);  // seconds
  const double elapsedTime(elapsedTimeSeconds.count() * 1000.0);  // milliseconds
  printf("Runtime is: %i iterations in %f milliseconds == %f iterations/second.\n", NUM_ITERATIONS,
    elapsedTime, ((double) NUM_ITERATIONS)*1000.0/elapsedTime);
  const double simulatedTime = ((double)blockSize / (double)sampleRate) * (double)NUM_ITERATIONS * 1000.0; // milliseconds
  printf("Runs in realtime: %s (x%.3f)\n", (simulatedTime >= elapsedTime) ? "YES" : "NO", simulatedTime/elapsedTime);
  
  zg_context_delete(context);
  free(inputBuffers);
  free(outputBuffers);
  
  return 0;
}
开发者ID:G4m4,项目名称:ZenGarden,代码行数:53,代码来源:main.cpp

示例14: GetMOPS

double IS::GetMOPS(std::chrono::duration<double> total_time,int niter,int num_keys)
{
	double mops = 0.0;

	double tt = total_time.count();

	if( tt > 0 )
	{
		mops = (double) niter+num_keys;
		mops *= niter / (tt*1000000.0);
	}

	return mops;
}
开发者ID:ggrunewald,项目名称:NPB3.0-Cpp,代码行数:14,代码来源:IS.cpp

示例15: assemble_mass

void dynamic_matrix::assemble_mass()
{
    M.resize(mesh.active_dofs(), mesh.active_dofs());

    std::vector<doublet<int>> doublets;
    doublets.reserve(mesh.active_dofs());

    for (auto const& submesh : mesh.meshes())
    {
        for (std::int64_t element = 0; element < submesh.elements(); element++)
        {
            auto const dof_view = submesh.local_dof_view(element);

            for (std::int64_t p{0}; p < dof_view.size(); ++p)
            {
                for (std::int64_t q{0}; q < dof_view.size(); ++q)
                {
                    doublets.emplace_back(dof_view(p), dof_view(q));
                }
            }
        }
    }
    M.setFromTriplets(doublets.begin(), doublets.end());

    doublets.clear();

    auto const start = std::chrono::steady_clock::now();

    for (auto const& submesh : mesh.meshes())
    {
        for (std::int64_t element = 0; element < submesh.elements(); ++element)
        {
            auto const& [dofs, m] = submesh.consistent_mass(element);

            for (std::int64_t a{0}; a < dofs.size(); a++)
            {
                for (std::int64_t b{0}; b < dofs.size(); b++)
                {
                    M.add_to(dofs(a), dofs(b), m(a, b));
                }
            }
        }
    }

    auto const end = std::chrono::steady_clock::now();
    std::chrono::duration<double> const elapsed_seconds = end - start;

    std::cout << std::string(6, ' ') << "Mass assembly took " << elapsed_seconds.count() << "s\n";
}
开发者ID:dbeurle,项目名称:neon,代码行数:49,代码来源:dynamic_matrix.cpp


注:本文中的std::chrono::duration::count方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。