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();
		}
	}
}
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();
    }
}
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();
}
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()));
}
Ejemplo n.º 5
0
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 ();
    }
}
Ejemplo n.º 6
0
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 ();
    }
}
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()));
}
Ejemplo n.º 8
0
 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);
 }
/*
 *	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();
  }
}
/* 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();
  }
}
Ejemplo n.º 11
0
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");
    }
}
/*
 *	Measure the time it takes for the logd posting call to make it into
 * the logs. Expect this to be less than double the process wakeup time (2ms).
 */
static void BM_log_delay(benchmark::State& state) {
  pid_t pid = getpid();

  struct logger_list* logger_list =
      android_logger_list_open(LOG_ID_EVENTS, ANDROID_LOG_RDONLY, 0, pid);

  if (!logger_list) {
    fprintf(stderr, "Unable to open events log: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }

  signal(SIGALRM, caught_delay);
  alarm(alarm_time);

  while (state.KeepRunning()) {
    log_time ts(CLOCK_REALTIME);

    LOG_FAILURE_RETRY(android_btWriteLog(0, EVENT_TYPE_LONG, &ts, sizeof(ts)));

    for (;;) {
      log_msg log_msg;
      int ret = android_logger_list_read(logger_list, &log_msg);
      alarm(alarm_time);

      if (ret <= 0) {
        state.SkipWithError("android_logger_list_read");
        break;
      }
      if ((log_msg.entry.len != (4 + 1 + 8)) ||
          (log_msg.id() != LOG_ID_EVENTS)) {
        continue;
      }

      char* eventData = log_msg.msg();

      if (!eventData || (eventData[4] != EVENT_TYPE_LONG)) {
        continue;
      }
      log_time tx(eventData + 4 + 1);
      if (ts != tx) {
        if (0xDEADBEEFA55A5AA6ULL == caught_convert(eventData + 4 + 1)) {
          state.SkipWithError("signal");
          break;
        }
        continue;
      }

      break;
    }
  }
  state.PauseTiming();

  signal(SIGALRM, SIG_DFL);
  alarm(0);

  android_logger_list_free(logger_list);
}
/*
 *	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();
  }
}
/*
 *	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();
  }
}
Ejemplo n.º 15
0
static void BENCH_enqueue(benchmark::State& state)
{
	while (state.KeepRunning())
	{
		state.PauseTiming();
		cgogn::ThreadPool* tp = cgogn::thread_pool();
		state.ResumeTiming();
		tp->enqueue([](uint32){;});
	}
}
Ejemplo n.º 16
0
static void BM_Constructor(benchmark::State& state)
{
  while (state.KeepRunning())
    {
      state.PauseTiming();
      typename Q::Domain dom(typename Q::Point().diagonal(0),
                             typename Q::Point().diagonal(state.range_x()));
      state.ResumeTiming();
      Q image( dom );
    }
}
Ejemplo n.º 17
0
static void BM_CoordFromIndex(benchmark::State& state)
{
	std::vector<ade::DimT> slist;
	for (auto _ : state)
	{
		state.PauseTiming();
		slist = random_vector<ade::rank_cap>(1, 255);
		ade::Shape shape(slist);
		ade::NElemT index = random_bignum(0, shape.n_elems());
		state.ResumeTiming();
		ade::coordinate(shape, index);
	}
}
Ejemplo n.º 18
0
void BM_DecodePi(benchmark::State& state) {  // NOLINT(runtime/references)
  bool correct = true;
  state.PauseTiming();
  std::vector<uint8_t> input_digits = Digits();
  std::vector<uint8_t> expected_bytes = Bytes();
  state.ResumeTiming();
  while (state.KeepRunning()) {
    HexDecode(&state, &correct, input_digits, expected_bytes);
  }
  std::stringstream ss;
  ss << correct;
  state.SetLabel(ss.str());
}
Ejemplo n.º 19
0
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()));
	}
}
Ejemplo n.º 20
0
static void BM_UNALIGNED(benchmark::State& state) {
  const int n{35};
  while (state.KeepRunning()) {
    state.PauseTiming();
    il::Array<float> v{n, 0.0f, il::align, 32, 16};
    state.ResumeTiming();
    for (il::int_t i{0}; i < v.size(); ++i) {
      v[i] = (v[i] / 5.3f) * (v[i] * v[i] + v[i]) - (12.5f / (v[i] + 0.3f)) +
             (v[i] / (14.3f / (v[i] + 1.4f))) - (v[i] / 23.0f) +
             (14.8f / (2.4f + v[i]));
    }
  }
}
static void BM_insert(benchmark::State& state)
{
  Q myset(typename Q::Domain( Q::Point::diagonal(0), Q::Point::diagonal(2048) ));
  while (state.KeepRunning())
    {
      state.PauseTiming();
      typename Q::Point p;
      for(unsigned int j=0; j < Q::Point::dimension; j++)
        p[j] = rand() % 2048;
      state.ResumeTiming();

      myset.insert( p );
   }
}
/*
 *	Measure the time it takes to submit the android event logging call
 * using discrete acquisition under light load with a known logtag.  Expect
 * this to be a dozen or so syscall periods (less than 40us)
 */
static void BM_log_event_overhead_42(benchmark::State& state) {
  for (int64_t i = 0; state.KeepRunning(); ++i) {
    // In system/core/logcat/event.logtags:
    // # These are used for testing, do not modify without updating
    // # tests/framework-tests/src/android/util/EventLogFunctionalTest.java.
    // # system/core/liblog/tests/liblog_benchmark.cpp
    // # system/core/liblog/tests/liblog_test.cpp
    // 42    answer (to life the universe etc|3)
    __android_log_btwrite(42, EVENT_TYPE_LONG, &i, sizeof(i));
    state.PauseTiming();
    logd_yield();
    state.ResumeTiming();
  }
}
Ejemplo n.º 23
0
static void BM_ImageSegmentation(benchmark::State& state) {
    while (state.KeepRunning()) {
        state.PauseTiming();
        const int num_imgs = 36;
        DataSetReader dsr(std::string(ASSETS_PATH) + "/squirrel");
        auto ds = dsr.load(num_imgs);

        state.ResumeTiming();
        for (auto idx = 0; idx < num_imgs; ++idx) {
            ds->getCamera(idx).setMask(Binarize(
                ds->getCamera(idx).getImage(), cv::Scalar(0, 0, 30)));
        }
    }
}
Ejemplo n.º 24
0
static void BM_SetValue(benchmark::State& state)
{
  std::set<typename Q::Point> data = ConstructRandomSet<typename Q::Point>(state.range_x(),state.range_x());

  int64_t cpt=0;
  while (state.KeepRunning())
    {
      state.PauseTiming();
      typename Q::Domain dom(typename Q::Point().diagonal(0),
                             typename Q::Point().diagonal(state.range_x()));
      Q image( dom );
      for(typename std::set<typename Q::Point>::const_iterator it = data.begin(), itend=data.end();
          it != itend; ++it)
        {
          state.ResumeTiming();
          image.setValue( *it , 42);
          state.PauseTiming();
          cpt++;
        }
    }
  // const int64_t items_processed =
    // static_cast<int64_t>(state.iterations())*state.range_x();
  state.SetItemsProcessed(cpt);
}
Ejemplo n.º 25
0
static void BM_ALIGNED(benchmark::State& state) {
  const int n{35};
  while (state.KeepRunning()) {
    state.PauseTiming();
    il::Array<float> v{n, 0.0f, il::align, 32, 0};
    state.ResumeTiming();
    float* const w{v.data()};
#pragma omp simd aligned(w : 32)
    for (il::int_t i{0}; i < v.size(); ++i) {
      w[i] = (w[i] / 5.3f) * (w[i] * w[i] + w[i]) - (12.5f / (w[i] + 0.3f)) +
             (w[i] / (14.3f / (w[i] + 1.4f))) - (w[i] / 23.0f) +
             (14.8f / (2.4f + w[i]));
    }
  }
}
Ejemplo n.º 26
0
template <size_t size> void bench_bitmapped_alloc(benchmark::State& s) {
    BitmappedBlock<Mallocator, size> alloc(batch_size);
    std::array<Block, batch_size> blocks;

    while (s.KeepRunning()) {
        for (auto& blk : blocks) {
            blk = alloc.allocate(size);
        }

        s.PauseTiming();
        for (auto& blk : blocks) {
            alloc.deallocate(blk);
        }
        s.ResumeTiming();
    }
}
Ejemplo n.º 27
0
static void BM_BoolinqCode (benchmark::State& state)
{
    while (state.KeepRunning () ) {
        double avgValue = from(vecBoolinq).where( [](int a){return a%2 == 1;})
                                   .avg<double>();

        double disper = from(vecBoolinq).where(  [](int a){return a%2 == 1;})
                                 .select([=](int a){return (double)((a-avgValue)*(a-avgValue));})
                                 .avg<double>();
        // It's no test, instead it's avoiding skip of calculation throgh optimization.
        state.PauseTiming ();
        EXPECT_TRUE(avgValue);
        EXPECT_TRUE(disper);
        state.ResumeTiming ();
    }
}
Ejemplo n.º 28
0
static void BENCH_faces_normals_single_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());
		FaceAttribute<Vec3> face_normal = bench_map.get_attribute<Vec3, FACE>("normal");
		cgogn_assert(face_normal.is_valid());
		state.ResumeTiming();

		bench_map.template foreach_cell<STRATEGY>([&] (Face f)
		{
			face_normal[f] = cgogn::geometry::normal<Vec3>(bench_map, f, vertex_position);
		});
	}
}
Ejemplo n.º 29
0
static void BM_BoundingBox(benchmark::State& state) {
    while (state.KeepRunning()) {
        state.PauseTiming();
        const int num_imgs = 36;
        DataSetReader dsr(std::string(ASSETS_PATH) + "/squirrel");
        auto ds = dsr.load(num_imgs);

        for (auto idx = 0; idx < num_imgs; ++idx) {
            ds->getCamera(idx).setMask(Binarize(
                ds->getCamera(idx).getImage(), cv::Scalar(0, 0, 30)));
        }
        state.ResumeTiming();
        BoundingBox bbox =
            BoundingBox(ds->getCamera(0), ds->getCamera((num_imgs / 4) - 1));
        auto vc = ret::make_unique<VoxelCarving>(bbox.getBounds(), 128);
    }
}
Ejemplo n.º 30
0
static void BM_CoordReduce(benchmark::State& state)
{
	ade::CoordT outcoord, coord;
	std::vector<ade::DimT> slist;
	for (auto _ : state)
	{
		state.PauseTiming();
		slist = random_vector<ade::rank_cap>(1, 255);
		ade::Shape shape(slist);
		ade::NElemT index = random_bignum(0, shape.n_elems());
		coord = ade::coordinate(shape, index);
		uint8_t rank = random_bignum(0, ade::rank_cap - 1);
		auto reducer = ade::reduce(rank,
			std::vector<ade::DimT>(slist.begin() + rank, slist.end()));
		state.ResumeTiming();
		reducer->forward(outcoord.begin(), coord.begin());
	}
}