本文整理汇总了C++中benchmark::State::ResumeTiming方法的典型用法代码示例。如果您正苦于以下问题:C++ State::ResumeTiming方法的具体用法?C++ State::ResumeTiming怎么用?C++ State::ResumeTiming使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类benchmark::State
的用法示例。
在下文中一共展示了State::ResumeTiming方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BENCH_vertices_normals_multi_threaded
static void BENCH_vertices_normals_multi_threaded(benchmark::State& state)
{
while(state.KeepRunning())
{
state.PauseTiming();
VertexAttribute<Vec3> vertex_position = bench_map.get_attribute<Vec3, VERTEX>("position");
cgogn_assert(vertex_position.is_valid());
VertexAttribute<Vec3> vertices_normal_mt = bench_map.get_attribute<Vec3, VERTEX>("normal_mt");
cgogn_assert(vertices_normal_mt.is_valid());
state.ResumeTiming();
bench_map.template parallel_foreach_cell<STRATEGY>([&] (Vertex v, uint32)
{
vertices_normal_mt[v] = cgogn::geometry::normal<Vec3>(bench_map, v, vertex_position);
});
{
state.PauseTiming();
VertexAttribute<Vec3> vertices_normal = bench_map.get_attribute<Vec3, VERTEX>("normal");
bench_map.template foreach_cell<cgogn::TraversalStrategy::FORCE_DART_MARKING>([&] (Vertex v)
{
Vec3 error = vertices_normal[v] - vertices_normal_mt[v];
if (!cgogn::almost_equal_absolute(error.squaredNorm(), 0., 1e-9 ))
{
cgogn_log_warning("bench_multithreading") << "There was an error during computation of vertices normals.";
// std::cerr << "vertices_normal " << vertices_normal[v] << std::endl;
// std::cerr << "vertices_normal_mt " << vertices_normal_mt[v] << std::endl;
}
});
state.ResumeTiming();
}
}
}
示例2: BM_client
static void BM_client(benchmark::State& state)
{
server();
int rv;
sp<IServiceManager> sm = defaultServiceManager();
// If needed bind to client CPU
if (options.clientCPU != unbound) { bindCPU(options.clientCPU); }
// Attach to service
sp<IBinder> binder;
for (int i = 0; i < 3; i++) {
binder = sm->getService(serviceName);
if (binder != 0) break;
cout << serviceName << " not published, waiting..." << endl;
usleep(500000); // 0.5 s
}
if (binder == 0) {
cout << serviceName << " failed to publish, aborting" << endl;
return;
}
unsigned int iter = 0;
// Perform the IPC operations in the benchmark
while (state.KeepRunning()) {
Parcel send, reply;
// Create parcel to be sent. Will use the iteration cound
// and the iteration count + 3 as the two integer values
// to be sent.
state.PauseTiming();
int val1 = iter;
int val2 = iter + 3;
int expected = val1 + val2; // Expect to get the sum back
send.writeInt32(val1);
send.writeInt32(val2);
state.ResumeTiming();
// Send the parcel, while timing how long it takes for
// the answer to return.
if ((rv = binder->transact(AddIntsService::ADD_INTS,
send, &reply)) != 0) {
cerr << "binder->transact failed, rv: " << rv
<< " errno: " << errno << endl;
exit(10);
}
state.PauseTiming();
int result = reply.readInt32();
if (result != (int) (iter + iter + 3)) {
cerr << "Unexpected result for iteration " << iter << endl;
cerr << " result: " << result << endl;
cerr << "expected: " << expected << endl;
}
if (options.iterDelay > 0.0) { testDelaySpin(options.iterDelay); }
state.ResumeTiming();
}
}
示例3: SolveHarmonicOscillatorAndComputeError3D
void SolveHarmonicOscillatorAndComputeError3D(benchmark::State& state,
Length& q_error,
Speed& v_error,
Integrator const& integrator) {
using ODE = SpecialSecondOrderDifferentialEquation<Position<World>>;
state.PauseTiming();
Displacement<World> const q_initial({1 * Metre, 0 * Metre, 0 * Metre});
Velocity<World> const v_initial;
Instant const t_initial;
#ifdef _DEBUG
Instant const t_final = t_initial + 100 * Second;
#else
Instant const t_final = t_initial + 1000 * Second;
#endif
Time const step = 3.0e-4 * Second;
std::vector<ODE::SystemState> solution;
solution.reserve(static_cast<int>((t_final - t_initial) / step));
ODE harmonic_oscillator;
harmonic_oscillator.compute_acceleration =
std::bind(ComputeHarmonicOscillatorAcceleration3D, _1, _2, _3);
IntegrationProblem<ODE> problem;
problem.equation = harmonic_oscillator;
ODE::SystemState const initial_state = {{World::origin + q_initial},
{v_initial},
t_initial};
problem.initial_state = &initial_state;
auto append_state = [&solution](ODE::SystemState const& state) {
solution.emplace_back(state);
};
auto const instance =
integrator.NewInstance(problem, std::move(append_state), step);
state.ResumeTiming();
integrator.Solve(t_final, *instance);
state.PauseTiming();
q_error = Length();
v_error = Speed();
for (auto const& state : solution) {
q_error = std::max(q_error,
((state.positions[0].value - World::origin) -
q_initial *
Cos((state.time.value - t_initial) *
(Radian / Second))).Norm());
v_error = std::max(v_error,
(state.velocities[0].value +
(q_initial / Second) *
Sin((state.time.value - t_initial) *
(Radian / Second))).Norm());
}
state.ResumeTiming();
}
示例4: BM_CppCode
static void BM_CppCode (benchmark::State& state)
{
while (state.KeepRunning () ) {
double sum = 0;
int count = 0;
for (unsigned i = 0; i < vecCpp.size(); i++)
{
if (vecCpp[i] % 2 == 1)
{
sum += vecCpp[i];
count++;
}
}
double avgValue = sum / count;
double disperSum = 0;
for (unsigned i = 0; i < vecCpp.size(); i++)
if (vecCpp[i] % 2 == 1)
disperSum += (vecCpp[i] - avgValue)*(vecCpp[i] - avgValue);
double disper = disperSum / count;
// It's no test, instead it's avoiding skip of calculation throgh optimization.
state.PauseTiming ();
EXPECT_TRUE(avgValue);
EXPECT_TRUE(disper);
state.ResumeTiming ();
}
}
示例5: SetUp
BENCHMARK_DEFINE_F(dynamic_default_fixture, max_threads)(benchmark::State& state) {
if (state.thread_index == 0) {
SetUp(state);
}
int nthreads = std::thread::hardware_concurrency();
sqeazy::frame_shuffle_scheme<std::uint16_t> local;
local.set_n_threads(nthreads);
local.encode(sinus_.data(),
output_.data(),
shape_);
while (state.KeepRunning()) {
state.PauseTiming();
std::fill(output_.begin(), output_.end(),0);
state.ResumeTiming();
local.encode(sinus_.data(),
output_.data(),
shape_);
}
state.SetBytesProcessed(int64_t(state.iterations()) *
int64_t(size_)*sizeof(sinus_.front()));
}
示例6: acquireTest
void acquireTest(benchmark::State& state_)
{
const std::size_t nblocks = state_.range(0);
Arena arena(sizeof(Arena::BlockHolder) * nblocks);
// Fill up the arena
std::vector<Arena::Block<int>*> ptrs;
for (int i = 0; i < nblocks; ++i) ptrs.push_back(arena.acquire<int>());
auto randRelease = [&arena, &ptrs](int fillRate_) {
// Randomly drop (1 - fillRate_) % of elements
for (auto ptr : ptrs) {
if (std::rand() % 100 < (100 - fillRate_)) arena.release(ptr);
}
};
long acquires = 0;
std::srand(0);
while (state_.KeepRunning()) {
state_.PauseTiming();
randRelease(state_.range(1));
state_.ResumeTiming();
auto ptr = arena.acquire<int>();
while (ptr) {
benchmark::DoNotOptimize(ptr = arena.acquire<int>());
benchmark::ClobberMemory();
++acquires;
}
}
state_.SetItemsProcessed(acquires);
}
示例7: BM_CppIterCode
static void BM_CppIterCode (benchmark::State& state)
{
while (state.KeepRunning () ) {
double sum = 0;
int count = 0;
for (auto it = vecCppIter.begin(); it != vecCppIter.end(); ++it)
{
if (*it % 2 == 1)
{
sum += *it;
count++;
}
}
double avgValue = sum / count;
double disperSum = 0;
for (auto it = vecCppIter.begin(); it != vecCppIter.end(); ++it)
if (*it % 2 == 1)
disperSum += (*it - avgValue)*(*it - avgValue);
double disper = disperSum / count;
// It's no test, instead it's avoiding skip of calculation throgh optimization.
state.PauseTiming ();
EXPECT_TRUE(avgValue);
EXPECT_TRUE(disper);
state.ResumeTiming ();
}
}
示例8: SetUp
BENCHMARK_DEFINE_F(dynamic_default_fixture, single_thread)(benchmark::State& state) {
if (state.thread_index == 0) {
SetUp(state);
}
sqeazy::remove_estimated_background_scheme<std::uint16_t> local;
local.set_n_threads(1);
local.encode(sinus_.data(),
output_.data(),
shape_);
while (state.KeepRunning()) {
state.PauseTiming();
std::fill(output_.begin(), output_.end(),0);
state.ResumeTiming();
local.encode(sinus_.data(),
output_.data(),
shape_);
}
state.SetBytesProcessed(int64_t(state.iterations()) *
int64_t(size_)*sizeof(sinus_.front()));
}
示例9: BM_log_light_overhead
/*
* Measure the time it takes to submit the android event logging call
* using discrete acquisition under very-light load (<1% CPU utilization).
*/
static void BM_log_light_overhead(benchmark::State& state) {
for (int64_t i = 0; state.KeepRunning(); ++i) {
__android_log_btwrite(0, EVENT_TYPE_LONG, &i, sizeof(i));
state.PauseTiming();
usleep(10000);
state.ResumeTiming();
}
}
示例10: BM_sprintf_overhead
/* performance test */
static void BM_sprintf_overhead(benchmark::State& state) {
while (state.KeepRunning()) {
test_print("BM_sprintf_overhead:%zu", state.iterations());
state.PauseTiming();
logd_yield();
state.ResumeTiming();
}
}
示例11: BM_Tangram_LoadFont
static void BM_Tangram_LoadFont(benchmark::State& state) {
while(state.KeepRunning()) {
state.PauseTiming();
std::shared_ptr<FontContext> m_ftContext;
m_ftContext = std::make_shared<FontContext>();
state.ResumeTiming();
m_ftContext->addFont("FiraSans-Medium.ttf", "FiraSans");
}
}
示例12: BM_log_event_overhead
/*
* Measure the time it takes to submit the android event logging call
* using discrete acquisition under light load. Expect this to be a long path
* to logger to convert the unknown tag (0) into a tagname (less than 200us).
*/
static void BM_log_event_overhead(benchmark::State& state) {
for (int64_t i = 0; state.KeepRunning(); ++i) {
// log tag number 0 is not known, nor shall it ever be known
__android_log_btwrite(0, EVENT_TYPE_LONG, &i, sizeof(i));
state.PauseTiming();
logd_yield();
state.ResumeTiming();
}
}
示例13: BM_log_print_overhead
/*
* Measure the time it takes to submit the android printing logging call
* using discrete acquisition discrete acquisition under light load. Expect
* this to be a dozen or so syscall periods (40us) plus time to run *printf
*/
static void BM_log_print_overhead(benchmark::State& state) {
while (state.KeepRunning()) {
__android_log_print(ANDROID_LOG_INFO, "BM_log_overhead", "%zu",
state.iterations());
state.PauseTiming();
logd_yield();
state.ResumeTiming();
}
}
示例14: BENCH_enqueue
static void BENCH_enqueue(benchmark::State& state)
{
while (state.KeepRunning())
{
state.PauseTiming();
cgogn::ThreadPool* tp = cgogn::thread_pool();
state.ResumeTiming();
tp->enqueue([](uint32){;});
}
}
示例15: BM_MakeReduce
static void BM_MakeReduce(benchmark::State& state)
{
std::vector<ade::DimT> slist;
for (auto _ : state)
{
state.PauseTiming();
slist = random_vector<ade::rank_cap>(1, 255);
uint8_t rank = random_bignum(0, ade::rank_cap - 1);
state.ResumeTiming();
ade::reduce(rank,
std::vector<ade::DimT>(slist.begin() + rank, slist.end()));
}
}