File indexing completed on 2025-01-18 09:12:27
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Tests/CommonHelpers/BenchmarkTools.hpp"
0010 #include "Acts/Utilities/BinUtility.hpp"
0011 #include "Acts/Utilities/Logger.hpp"
0012
0013 #include <algorithm>
0014 #include <vector>
0015
0016 #include <boost/program_options.hpp>
0017
0018 namespace po = boost::program_options;
0019 using namespace Acts;
0020
0021 int main(int argc, char* argv[]) {
0022 unsigned int lvl = Acts::Logging::INFO;
0023 unsigned int toys = 1;
0024
0025 try {
0026 po::options_description desc("Allowed options");
0027
0028 desc.add_options()
0029 ("help", "produce help message")
0030 ("toys",po::value<unsigned int>(&toys)->default_value(100000000),"number searches to be done")
0031 ("verbose",po::value<unsigned int>(&lvl)->default_value(Acts::Logging::INFO),"logging level");
0032
0033 po::variables_map vm;
0034 po::store(po::parse_command_line(argc, argv, desc), vm);
0035 po::notify(vm);
0036
0037 if (vm.contains("help")) {
0038 std::cout << desc << std::endl;
0039 return 0;
0040 }
0041 } catch (std::exception& e) {
0042 std::cerr << "error: " << e.what() << std::endl;
0043 return 1;
0044 }
0045
0046 ACTS_LOCAL_LOGGER(getDefaultLogger("BinUtility", Acts::Logging::Level(lvl)));
0047
0048 std::vector<float> fewBins;
0049 fewBins.reserve(6);
0050 for (unsigned int ib = 0; ib < 6; ++ib) {
0051 fewBins.push_back(ib * 6. / 5.);
0052 }
0053 Acts::BinUtility small(fewBins, Acts::open, Acts::AxisDirection::AxisX);
0054
0055 std::vector<float> mediumBins;
0056 mediumBins.reserve(21);
0057 for (unsigned int ib = 0; ib < 21; ++ib) {
0058 mediumBins.push_back(ib * 6. / 20.);
0059 }
0060 Acts::BinUtility medium(mediumBins, Acts::open, Acts::AxisDirection::AxisX);
0061
0062 std::vector<float> manyBins;
0063 manyBins.reserve(101);
0064 for (unsigned int ib = 0; ib < 101; ++ib) {
0065 manyBins.push_back(ib * 6. / 100.);
0066 }
0067
0068 Acts::BinUtility many(manyBins, Acts::open, Acts::AxisDirection::AxisX);
0069
0070 Acts::Vector3 low = Acts::Vector3(1.5, 0., 0.);
0071 Acts::Vector3 high = Acts::Vector3(4.5, 0., 0.);
0072
0073 std::size_t st = 0;
0074 std::size_t gt = 0;
0075 std::size_t num_iters = 0;
0076 const auto bin_utility_benchmark_small = Acts::Test::microBenchmark(
0077 [&] {
0078 auto bin = (num_iters % 2) != 0u ? small.bin(low) : small.bin(high);
0079 if (bin < 3) {
0080 ++st;
0081 } else {
0082 ++gt;
0083 }
0084 ++num_iters;
0085 },
0086 1, toys);
0087
0088 ACTS_INFO("Execution stats small: " << bin_utility_benchmark_small);
0089 ACTS_INFO("Fraction is: " << st << " vs. " << gt);
0090
0091 st = 0;
0092 gt = 0;
0093 num_iters = 0;
0094 const auto bin_utility_benchmark_medium = Acts::Test::microBenchmark(
0095 [&] {
0096 auto bin = (num_iters % 2) != 0u ? medium.bin(low) : medium.bin(high);
0097 if (bin < 10) {
0098 ++st;
0099 } else {
0100 ++gt;
0101 }
0102 ++num_iters;
0103 },
0104 1, toys);
0105
0106 ACTS_INFO("Execution stats medium: " << bin_utility_benchmark_medium);
0107 ACTS_INFO("Fraction is: " << st << " vs. " << gt);
0108
0109 st = 0;
0110 gt = 0;
0111 num_iters = 0;
0112 const auto bin_utility_benchmark_many = Acts::Test::microBenchmark(
0113 [&] {
0114 auto bin = (num_iters % 2) != 0u ? many.bin(low) : many.bin(high);
0115 if (bin < 49) {
0116 ++st;
0117 } else {
0118 ++gt;
0119 }
0120 ++num_iters;
0121 },
0122 1, toys);
0123
0124 ACTS_INFO("Execution stats many: " << bin_utility_benchmark_many);
0125 ACTS_INFO("Fraction is: " << st << " vs. " << gt);
0126
0127 Acts::BinUtility equidistant(100, 0., 6., Acts::open,
0128 Acts::AxisDirection::AxisX);
0129 st = 0;
0130 gt = 0;
0131 num_iters = 0;
0132 const auto bin_utility_benchmark_eq = Acts::Test::microBenchmark(
0133 [&] {
0134 auto bin = (num_iters % 2) != 0u ? equidistant.bin(low)
0135 : equidistant.bin(high);
0136 if (bin < 49) {
0137 ++st;
0138 } else {
0139 ++gt;
0140 }
0141 ++num_iters;
0142 },
0143 1, toys);
0144
0145 ACTS_INFO("Execution stats equidistant: " << bin_utility_benchmark_eq);
0146 ACTS_INFO("Fraction is: " << st << " vs. " << gt);
0147
0148 return 0;
0149 }