本文整理汇总了C++中Stopwatch::restart方法的典型用法代码示例。如果您正苦于以下问题:C++ Stopwatch::restart方法的具体用法?C++ Stopwatch::restart怎么用?C++ Stopwatch::restart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stopwatch
的用法示例。
在下文中一共展示了Stopwatch::restart方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int, char **)
try
{
std::cout << std::fixed << std::setprecision(2);
size_t n = 100000000;
Stopwatch stopwatch;
{
DB::WriteBufferFromFile buf("test_zlib_buffers.gz", DBMS_DEFAULT_BUFFER_SIZE, O_WRONLY | O_CREAT | O_TRUNC);
DB::ZlibDeflatingWriteBuffer deflating_buf(buf, DB::CompressionMethod::Gzip, /* compression_level = */ 3);
stopwatch.restart();
for (size_t i = 0; i < n; ++i)
{
DB::writeIntText(i, deflating_buf);
DB::writeChar('\t', deflating_buf);
}
deflating_buf.finish();
stopwatch.stop();
std::cout << "Writing done. Elapsed: " << stopwatch.elapsedSeconds() << " s."
<< ", " << (deflating_buf.count() / stopwatch.elapsedSeconds() / 1000000) << " MB/s"
<< std::endl;
}
{
DB::ReadBufferFromFile buf("test_zlib_buffers.gz");
DB::ZlibInflatingReadBuffer inflating_buf(buf, DB::CompressionMethod::Gzip);
stopwatch.restart();
for (size_t i = 0; i < n; ++i)
{
size_t x;
DB::readIntText(x, inflating_buf);
inflating_buf.ignore();
if (x != i)
throw DB::Exception("Failed!, read: " + std::to_string(x) + ", expected: " + std::to_string(i), 0);
}
stopwatch.stop();
std::cout << "Reading done. Elapsed: " << stopwatch.elapsedSeconds() << " s."
<< ", " << (inflating_buf.count() / stopwatch.elapsedSeconds() / 1000000) << " MB/s"
<< std::endl;
}
return 0;
}
catch (const DB::Exception & e)
{
std::cerr << e.what() << ", " << e.displayText() << std::endl;
return 1;
}
示例2: init
/// <summary>
/// 最初のシーンを初期化します。
/// </summary>
/// <param name="state">
/// 最初のシーン
/// </param>
/// <returns>
/// 初期化に成功した場合 true, それ以外の場合は false
/// </returns>
bool init(const State& state)
{
if (m_current)
{
return false;
}
auto it = m_factories.find(state);
if (it == m_factories.end())
{
return false;
}
m_currentState = state;
m_current = it->second();
if (hasError())
{
return false;
}
m_transitionState = TransitionState::FadeIn;
m_stopwatch.restart();
return true;
}
示例3: update
void update(bool currentPressed)
{
const bool previousPressed = pressed;
pressed = currentPressed;
down = !previousPressed && pressed;
up = previousPressed && !pressed;
if (down)
{
stopwatch.restart();
}
else if (up)
{
pressedDuration = stopwatch.elapsedF();
stopwatch.reset();
}
else if (pressed)
{
pressedDuration = stopwatch.elapsedF();
}
else
{
pressedDuration = MillisecondsF(0);
}
}
示例4: run
void run()
{
std::mt19937 generator(randomSeed());
std::uniform_int_distribution<size_t> distribution(0, queries.size() - 1);
for (size_t i = 0; i < concurrency; ++i)
pool.schedule(std::bind(&Benchmark::thread, this, connections.get()));
InterruptListener interrupt_listener;
info_per_interval.watch.restart();
delay_watch.restart();
/// Push queries into queue
for (size_t i = 0; !max_iterations || i < max_iterations; ++i)
{
size_t query_index = randomize ? distribution(generator) : i % queries.size();
if (!tryPushQueryInteractively(queries[query_index], interrupt_listener))
break;
}
shutdown = true;
pool.wait();
info_total.watch.stop();
if (!json_path.empty())
reportJSON(info_total, json_path);
printNumberOfQueriesExecuted(info_total.queries);
report(info_total);
}
示例5:
ADD_TEST(StopWatchTest, TestAll) {
Stopwatch sw;
sw.start();
this_thread::sleep_for(chrono::milliseconds(200));
sw.stop();
Int64 d = sw.elapsed();
CHECK(d > 180000);
CHECK(d < 300000);
sw.start();
this_thread::sleep_for(chrono::milliseconds(100));
sw.stop();
d = sw.elapsed();
CHECK(d > 280000);
CHECK(d < 400000);
this_thread::sleep_for(chrono::milliseconds(100));
sw.stop();
d = sw.elapsed();
CHECK(d > 380000);
CHECK(d < 500000);
sw.restart();
sw.start();
this_thread::sleep_for(chrono::milliseconds(200));
sw.stop();
d = sw.elapsed();
CHECK(d > 180000);
CHECK(d < 300000);
}
示例6: restart
/// <summary>
/// 経過時間を0にリセットして、EasingControllerを開始します。
/// </summary>
/// <returns>
/// なし
/// </returns>
void restart()
{
std::swap(m_start, m_end);
m_swapped = true;
m_stopwatch.restart();
}
示例7: clear
void clear()
{
pressedDuration = MillisecondsF(0);
stopwatch.restart();
up = pressed = down = false;
}
示例8: changeScene
/// <summary>
/// シーンを変更します。
/// </summary>
/// <param name="state">
/// 次のシーンのキー
/// </param>
/// <param name="transitionTimeMillisec">
/// フェードイン・アウトの時間(ミリ秒)
/// </param>
/// <param name="crossFade">
/// クロスフェードを有効にするか
/// </param>
/// <returns>
/// シーンの変更が可能でフェードイン・アウトが開始される場合 true, それ以外の場合は false
/// </returns>
bool changeScene(const State& state, int32 transitionTimeMillisec, bool crossFade)
{
if (state == m_currentState)
{
crossFade = false;
}
if (m_factories.find(state) == m_factories.end())
{
return false;
}
m_nextState = state;
m_crossFade = crossFade;
if (crossFade)
{
m_transitionTimeMillisec = transitionTimeMillisec;
m_transitionState = TransitionState::FadeInOut;
m_next = m_factories[m_nextState]();
if (hasError())
{
return false;
}
m_currentState = m_nextState;
m_stopwatch.restart();
}
else
{
m_transitionTimeMillisec = (transitionTimeMillisec / 2);
m_transitionState = TransitionState::FadeOut;
m_stopwatch.restart();
}
return true;
}
示例9: main
/// This test is useful for assessing the performance of acquiring block numbers in all partitions (and there
/// can be ~1000 of them). This is needed when creating a mutation entry for a ReplicatedMergeTree table.
int main(int argc, char ** argv)
try
{
if (argc != 3)
{
std::cerr << "usage: " << argv[0] << " <zookeeper_config> <path_to_table>" << std::endl;
return 3;
}
ConfigProcessor processor(argv[1], false, true);
auto config = processor.loadConfig().configuration;
String root_path = argv[2];
zkutil::ZooKeeper zk(*config, "zookeeper");
String temp_path = root_path + "/temp";
String blocks_path = root_path + "/block_numbers";
Stopwatch total_timer;
Stopwatch timer;
EphemeralLocksInAllPartitions locks(blocks_path, "test_lock-", temp_path, zk);
std::cerr << "Locked, elapsed: " << timer.elapsedSeconds() << std::endl;
for (const auto & lock : locks.getLocks())
std::cout << lock.partition_id << " " << lock.number << std::endl;
timer.restart();
locks.unlock();
std::cerr << "Abandoned, elapsed: " << timer.elapsedSeconds() << std::endl;
std::cerr << "Total elapsed: " << total_timer.elapsedSeconds() << std::endl;
return 0;
}
catch (const Exception & e)
{
std::cerr << e.what() << ", " << e.displayText() << ": " << std::endl
<< e.getStackTrace().toString() << std::endl;
throw;
}
catch (Poco::Exception & e)
{
std::cerr << "Exception: " << e.displayText() << std::endl;
throw;
}
catch (std::exception & e)
{
std::cerr << "std::exception: " << e.what() << std::endl;
throw;
}
catch (...)
{
std::cerr << "Some exception" << std::endl;
throw;
}
示例10: clear
void clear()
{
watch.restart();
queries = 0;
read_rows = 0;
read_bytes = 0;
result_rows = 0;
result_bytes = 0;
sampler.clear();
}
示例11: source_indicies
vector<Correspondence3D> KeypointsCorrespondenceProjector::findLidarCorrespondences()
{
Stopwatch stopwatch;
stopwatch.restart();
cv::flann::KDTreeIndexParams index_params(1);
Mat source_image_keypoints = getTrainingPointsFromImageMatches(SOURCE);
cv::flann::Index source_kdTree(source_image_keypoints, index_params);
Mat target_image_keypoints = getTrainingPointsFromImageMatches(TARGET);
cv::flann::Index target_kdTree(target_image_keypoints, index_params);
Mat source_query = createQueryFromProjectedCloud(source_projection);
Mat source_indicies(source_query.rows, 1, CV_32SC1);
Mat source_distances(source_query.rows, 1, CV_32FC1);
source_kdTree.knnSearch(source_query, source_indicies, source_distances, 1);
/*draw3DTo2DMatches(source_image,
source_projection,
images_correspondences,
SOURCE,
source_indicies);*/
Mat target_query = createQueryFromProjectedCloud(target_projection);
Mat target_indicies(target_query.rows, 1, CV_32SC1);
Mat target_distances(target_query.rows, 1, CV_32FC1);
target_kdTree.knnSearch(target_query, target_indicies, target_distances, 1);
/*draw3DTo2DMatches(target_image,
target_projection,
images_correspondences,
TARGET,
target_indicies);*/
cerr << "Nearest projected points found in: " << stopwatch.elapsed() << "[sec]" << endl;
stopwatch.restart();
vector<Correspondence3D> final_correspondences = mergeCorrespondences(source_indicies,
source_distances,
target_indicies,
target_distances);
cerr << "Merged in: " << stopwatch.elapsed() << "[sec]" << endl;
cerr << "Correspondences projected: " << final_correspondences.size();
return final_correspondences;
}
示例12: main
int main()
{
Stopwatch sw;
sw.restart();
int maxtime = 2;
while(sw.getTime()<maxtime) {
printf("%f \n",sw.getTime());
}
sw.stop();
printf("end time = %f \n",sw.getTime());
}
示例13: main
int main()
{
const int iterations = 1000000;
double sqrtsum = 0;
Stopwatch<> sw;
for (int i=0; i<iterations; ++i)
sqrtsum += sqrt(i);
std::cout << "calculated " << sqrtsum << " in " << sw.restart() << " us\n";
sqrtsum = 0;
for (int i=0; i<iterations; ++i)
sqrtsum += pow(i,0.5);
std::cout << "calculated " << sqrtsum << " in " << sw.stop() << " us\n";
}
示例14: testPoll
void SocketTest::testPoll()
{
EchoServer echoServer;
StreamSocket ss;
ss.connect(SocketAddress("localhost", echoServer.port()));
Stopwatch sw;
sw.start();
Timespan timeout(1000000);
assert (!ss.poll(timeout, Socket::SELECT_READ));
assert (sw.elapsed() >= 900000);
sw.restart();
assert (ss.poll(timeout, Socket::SELECT_WRITE));
assert (sw.elapsed() < 100000);
ss.sendBytes("hello", 5);
char buffer[256];
sw.restart();
assert (ss.poll(timeout, Socket::SELECT_READ));
assert (sw.elapsed() < 100000);
int n = ss.receiveBytes(buffer, sizeof(buffer));
assert (n == 5);
assert (std::string(buffer, n) == "hello");
ss.close();
}
示例15: testTimer
void TimerTest::testTimer()
{
Timer t(100, 200);
assert (t.getStartInterval() == 100);
assert (t.getPeriodicInterval() == 200);
Stopwatch sw;
TimerCallback<TimerTest> tc(*this, &TimerTest::onTimer);
sw.start();
t.start(tc);
_event.wait();
sw.stop();
assert (sw.elapsed() >= 80000 && sw.elapsed() < 250000);
sw.restart();
_event.wait();
sw.stop();
assert (sw.elapsed() >= 180000 && sw.elapsed() < 250000);
sw.restart();
_event.wait();
sw.stop();
assert (sw.elapsed() >= 180000 && sw.elapsed() < 250000);
t.stop();
}