本文整理汇总了C++中milliseconds::count方法的典型用法代码示例。如果您正苦于以下问题:C++ milliseconds::count方法的具体用法?C++ milliseconds::count怎么用?C++ milliseconds::count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类milliseconds
的用法示例。
在下文中一共展示了milliseconds::count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addFunctionUniformDistribution
void FunctionScheduler::addFunctionUniformDistribution(
Function<void()>&& cb,
milliseconds minInterval,
milliseconds maxInterval,
StringPiece nameID,
milliseconds startDelay) {
addFunctionGenericDistribution(
std::move(cb),
UniformDistributionFunctor(minInterval, maxInterval),
nameID.str(),
to<std::string>(
"[", minInterval.count(), " , ", maxInterval.count(), "] ms"),
startDelay);
}
示例2: ReadImage
Image ReadImage(tjhandle tj, int width, int height, int quality = 75) {
static std::vector< char > img;
static int count = 0;
img.resize(3 * width * height);
glReadBuffer(GL_FRONT);
#ifdef TIME_READPIXEL
using namespace std::chrono;
steady_clock::time_point t = steady_clock::now();
#endif
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, &img[0]);
#ifdef TIME_READPIXEL
const milliseconds E =
duration_cast< milliseconds >(steady_clock::now() - t);
cout << E.count() << ' '; //doesn't flush, prints after closing window
#endif
char* out = nullptr;
unsigned long size = 0;
tjCompress2(tj,
(unsigned char*) &img[0],
width,
3 * width,
height,
TJPF_RGB,
(unsigned char **) &out,
&size,
TJSAMP_444,
quality,
0);
return Image(ImagePtr((char*) out, TJDeleter()), size, count++);
}
示例3: set_timeout
void SocketImpl::set_timeout( const milliseconds& value )
{
tcp::socket::native_handle_type native_socket(0);
#ifdef BUILD_SSL
if ( m_socket not_eq nullptr )
{
#endif
native_socket = m_socket->native_handle( );
#ifdef BUILD_SSL
}
else
{
native_socket = m_ssl_socket->lowest_layer( ).native_handle( );
}
#endif
struct timeval timeout = { 0, 0 };
timeout.tv_usec = static_cast< long >( value.count( ) * 1000 );
int status = setsockopt( native_socket, SOL_SOCKET, SO_SNDTIMEO, reinterpret_cast< char* >( &timeout ), sizeof( timeout ) );
if ( status == -1 and m_logger not_eq nullptr )
{
m_logger->log( Logger::Level::WARNING, "Failed to set socket option, send timeout." );
}
status = setsockopt( native_socket, SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast< char* >( &timeout ), sizeof( timeout ) );
if ( status == -1 and m_logger not_eq nullptr )
{
m_logger->log( Logger::Level::WARNING, "Failed to set socket option, receive timeout." );
}
}
示例4: main
int main(int argc, char **argv)
{
if (argc < 4) {
puts("Usage: ./out $num_passengers $capacity $time_interval $cycles");
exit(1);
}
int num_passengers = stoi(argv[1]),
capacity = stoi(argv[2]),
time_interval = stoi(argv[3]),
cycles = stoi(argv[4]);
pthread_t passenger_threads[num_passengers];
pthread_t coaster_thread;
s = high_resolution_clock::now();
RollerCoaster coaster_car = RollerCoaster(capacity, time_interval, cycles);
Passenger* passengers[num_passengers];
pthread_create(&coaster_thread, NULL, roller_coaster, (void*) &coaster_car);
for (int i = 0; i < num_passengers; ++i) {
passengers[i] = new Passenger(i + 1, coaster_car);
pthread_create(&passenger_threads[i], NULL, passenger, (void*) passengers[i]);
}
for (int i = 0; i < num_passengers; ++i) pthread_join(passenger_threads[i], NULL);
pthread_join(coaster_thread, NULL);
cout << "Total waiting time of all passengers: " << wait_time.count() << " millisec\n";
return 0;
}
示例5: addFunction
void FunctionScheduler::addFunction(Function<void()>&& cb,
milliseconds interval,
StringPiece nameID,
milliseconds startDelay) {
addFunctionGenericDistribution(
std::move(cb),
ConstIntervalFunctor(interval),
nameID.str(),
to<std::string>(interval.count(), "ms"),
startDelay);
}
示例6: dist
bool
WeightedLoadBalancerStrategy::mySendInterest(const Interest& interest,
shared_ptr<MyMeasurementInfo>& measurementsEntryInfo,
shared_ptr<pit::Entry>& pitEntry)
{
typedef MyMeasurementInfo::WeightedFaceSetByDelay WeightedFaceSetByDelay;
const WeightedFaceSetByDelay& facesByDelay =
measurementsEntryInfo->weightedFaces.get<MyMeasurementInfo::ByDelay>();
const milliseconds totalDelay = measurementsEntryInfo->totalDelay;
const milliseconds inverseTotalDelay =
MyMeasurementInfo::calculateInverseDelaySum(measurementsEntryInfo);
boost::random::uniform_int_distribution<> dist(0, inverseTotalDelay.count());
const uint64_t selection = dist(m_randomGenerator);
NFD_LOG_TRACE("selection = " << selection);
uint64_t cumulativeWeight = 0;
for (WeightedFaceSetByDelay::const_iterator i = facesByDelay.begin();
i != facesByDelay.end();
++i)
{
NFD_LOG_TRACE("cumulative weight = " << cumulativeWeight);
// weight = inverted delay measurement
const uint64_t weight = totalDelay.count() - i->lastDelay.count();
cumulativeWeight += weight;
if(selection <= cumulativeWeight && pitEntry->canForwardTo(i->face))
{
NFD_LOG_TRACE("fowarding " << interest.getName() << " out face " << i->face.getId());
this->sendInterest(pitEntry, this->getFace(i->face.getId()));
return true;
}
}
return false;
}
示例7: update
void Transition::update(milliseconds elapsed)
{
switch (state_)
{
case State::empty:
case State::full:
return;
case State::increase:
progress_ += static_cast<float>(elapsed.count()) / time_to_complete_.count();
if (progress_ >= 1.0f) {
progress_ = 1.0f;
state_ = State::full;
}
break;
case State::decrease:
progress_ -= static_cast<float>(elapsed.count()) / time_to_complete_.count();
if (progress_ <= 0.0f) {
progress_ = 0.0f;
state_ = State::empty;
}
break;
}
}
示例8: initTimerEngine
void AppState::initTimerEngine() {
const milliseconds interval(1);
const milliseconds dueTime(0);
//创建定时器,无属性,自动复位,匿名
HANDLE handle = CreateWaitableTimer(NULL, FALSE, NULL);
LARGE_INTEGER liDueTime;
liDueTime.QuadPart = -(nanoseconds(dueTime).count() / 100);
if (!SetWaitableTimer(handle, &liDueTime, interval.count(), NULL, NULL, FALSE)) {
throw std::runtime_error("dispatcherTimerEngine init error!");
}
DispatcherTimerEngine& engine = DispatcherTimerEngine::instance();
engine.setInterval(interval);
engine.start(dueTime);
//添加等待对象,以及触发事件
addEventHandle(handle, std::bind(&DispatcherTimerEngine::update, &engine));
}
示例9: mLogger
log_entry::log_entry(logger& l, logger::LogLevel level):
mLogger(l),
mLevel(level)
{
if(mLevel < 0) return;
using namespace std::chrono;
const milliseconds ms = duration_cast<milliseconds>(system_clock::now().time_since_epoch());
const seconds s = duration_cast<seconds>(ms);
const std::time_t t = s.count();
const std::size_t fractional_seconds = ms.count() % 1000;
mLogger.lock();
const char timeFormat[] = "%Y-%m-%d %H:%M:%S";
const size_t buffSize = 100;
char buff[buffSize];
if(0 != std::strftime(buff, buffSize, timeFormat, std::localtime(&t)))
{
mLogger.get() << buff;
}
else
{
size_t dBuffSize = buffSize;
std::unique_ptr<char[]> dbuff;
do
{
dBuffSize *= 2;
dbuff.reset(new char[dBuffSize]);
}
while(0 == std::strftime(dbuff.get(), dBuffSize, timeFormat, std::localtime(&t)));
mLogger.get() << dbuff.get();
}
mLogger.get() << '.' << fractional_seconds << " ";
if(level >= 0 && level <= logger::logDEBUG)
{
const char* levels[] = {"ERROR","WARNING","INFO","DEBUG"};
mLogger.get() << levels[level];
}
mLogger.get() << ": ";
}
示例10: ReadImage
Image ReadImage(int width, int height,
float quality = 100) {
static std::vector< char > img;
static int count = 0;
img.resize(3 * width * height);
glReadBuffer(GL_FRONT);
#ifdef TIME_READPIXEL
using namespace std::chrono;
steady_clock::time_point t = steady_clock::now();
#endif
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, &img[0]);
#ifdef TIME_READPIXEL
const milliseconds E =
duration_cast< milliseconds >(steady_clock::now() - t);
cout << E.count() << ' '; //doesn't flush, prints after closing window
#endif
uint8_t* out;
const size_t size =
WebPEncodeRGB((uint8_t*) &img[0], width, height, 3 * width,
quality, &out);
return Image(ImagePtr((char*) out, WebpDeleter()), size, count++);
}
示例11: output
void SimpleThinkingWriter::output(const ChessBoard& board,
const SearchResult& result,
const vector<Move>& main_variation,
const int nodes,
const milliseconds& time,
const Searcher::depth_t depth)
{
if (!post()) {
return;
}
ostringstream oss;
int turn_number = board.turn_number();
int ply = 0;
if (board.turn_color() == Color::Black) {
oss << turn_number << ". ... ";
++turn_number;
++ply;
}
for (const Move move : main_variation) {
if (ply % 2 == 0) {
oss << " " << turn_number << ".";
++turn_number;
}
oss << " " << move.source() << move.destination();
if (move.is_promotion()) {
oss << PieceSet::instance().piece(move.created_piece()).symbol(Color::Black);
}
++ply;
}
const int score = board.turn_color() == Color::White ? result.score : -result.score;
m_writer->thinking_output(depth,
score,
time.count() / 10,
nodes,
oss.str());
} // namespace olaf
示例12: set_resend_interval
void set_resend_interval(socket &s, milliseconds i)
{ s.setopt(REQ, REQ_RESEND_IVL, static_cast<int>(i.count())); }
示例13: sleep_for
void sleep_for(milliseconds d) {
// usleep is nanoseconds.
usleep (d.count() * 1000);
}
示例14:
Timer::Timer(milliseconds expiration_time, bool start_active) :
current_time_{ start_active ? 0 : expiration_time.count() + 1},
expiration_time_{expiration_time}
{
timers_.insert(this);
}
示例15: onTimer
void PoolingAcceptor::onTimer(const milliseconds& delta) {
LOG(INFO)<< "[" << __FUNCTION__ << "] " << delta.count();
}