File indexing completed on 2025-01-18 09:12:27
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/EventData/VectorMultiTrajectory.hpp"
0010 #include "Acts/Geometry/GeometryIdentifier.hpp"
0011 #include "Acts/Tests/CommonHelpers/BenchmarkTools.hpp"
0012
0013 #include <iostream>
0014 #include <type_traits>
0015
0016 using namespace Acts;
0017
0018 class BenchmarkSourceLink final {
0019 public:
0020 using Index = std::uint32_t;
0021
0022
0023 constexpr BenchmarkSourceLink(Acts::GeometryIdentifier gid, Index idx)
0024 : m_geometryId(gid), m_index(idx) {}
0025
0026 BenchmarkSourceLink() = default;
0027 BenchmarkSourceLink(const BenchmarkSourceLink&) = default;
0028 BenchmarkSourceLink(BenchmarkSourceLink&&) = default;
0029 BenchmarkSourceLink& operator=(const BenchmarkSourceLink&) = default;
0030 BenchmarkSourceLink& operator=(BenchmarkSourceLink&&) = default;
0031
0032
0033 constexpr Index index() const { return m_index; }
0034
0035 Acts::GeometryIdentifier geometryId() const { return m_geometryId; }
0036
0037 private:
0038 Acts::GeometryIdentifier m_geometryId;
0039 Index m_index = 0;
0040
0041 friend bool operator==(const BenchmarkSourceLink& lhs,
0042 const BenchmarkSourceLink& rhs) {
0043 return (lhs.geometryId() == rhs.geometryId()) &&
0044 (lhs.m_index == rhs.m_index);
0045 }
0046 };
0047
0048 int main(int , char** ) {
0049 std::size_t n = 100000;
0050
0051 VectorMultiTrajectory mtj;
0052
0053 GeometryIdentifier gid;
0054 gid.setVolume(5);
0055 gid.setLayer(3);
0056 gid.setSensitive(1);
0057
0058 static_assert(sizeof(BenchmarkSourceLink) <= ACTS_SOURCELINK_SBO_SIZE);
0059
0060 static_assert(std::is_trivially_move_constructible_v<BenchmarkSourceLink>);
0061
0062 BenchmarkSourceLink bsl{gid, 1234};
0063
0064 std::cout << "Creating source link" << std::endl;
0065 auto sourceLinkConstruction = Acts::Test::microBenchmark(
0066 [&]() {
0067 SourceLink sl{bsl};
0068 return sl;
0069 },
0070 n);
0071 std::cout << " " << sourceLinkConstruction << std::endl;
0072
0073 std::vector<SourceLink> inputs;
0074 inputs.reserve(n);
0075 for (std::size_t i = 0; i < n; ++i) {
0076 inputs.emplace_back(bsl);
0077 }
0078
0079 std::cout << "Copy construct source link" << std::endl;
0080 auto copyConstructSourceLink = Acts::Test::microBenchmark(
0081 [&](const SourceLink& input) {
0082 SourceLink copy{input};
0083 return copy;
0084 },
0085 inputs);
0086 std::cout << copyConstructSourceLink << std::endl;
0087
0088 std::cout << "Copy then move construct source link" << std::endl;
0089 auto copyMoveConstructSourceLink = Acts::Test::microBenchmark(
0090 [&](const SourceLink& input) {
0091 SourceLink copy{input};
0092 SourceLink mv{std::move(copy)};
0093 return mv;
0094 },
0095 inputs);
0096 std::cout << copyMoveConstructSourceLink << std::endl;
0097
0098 std::cout << "Optional assignment" << std::endl;
0099 auto opt_assignment = Acts::Test::microBenchmark(
0100 [&]() {
0101 SourceLink sl{bsl};
0102
0103 std::optional<SourceLink> opt;
0104 opt = std::move(sl);
0105 return opt;
0106 },
0107 n);
0108 std::cout << opt_assignment << std::endl;
0109
0110
0111 std::cout << "Create track state" << std::endl;
0112 auto create_track_state = Acts::Test::microBenchmark(
0113 [&]() {
0114 auto ts = mtj.makeTrackState(TrackStatePropMask::None);
0115 return ts;
0116 },
0117 n / 10);
0118 std::cout << create_track_state << std::endl;
0119
0120 std::cout << "Assign source link to track state" << std::endl;
0121 auto assignSourceLink = Acts::Test::microBenchmark(
0122 [&]() {
0123 SourceLink sl{bsl};
0124 auto ts = mtj.makeTrackState(TrackStatePropMask::None);
0125 ts.setUncalibratedSourceLink(std::move(sl));
0126 return ts;
0127 },
0128 n / 10);
0129 std::cout << assignSourceLink << std::endl;
0130
0131 return 0;
0132 }