File indexing completed on 2025-07-11 07:51:04
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 auto gid = GeometryIdentifier().withVolume(5).withLayer(3).withSensitive(1);
0054
0055 static_assert(sizeof(BenchmarkSourceLink) <= ACTS_SOURCELINK_SBO_SIZE);
0056
0057 static_assert(std::is_trivially_move_constructible_v<BenchmarkSourceLink>);
0058
0059 BenchmarkSourceLink bsl{gid, 1234};
0060
0061 std::cout << "Creating source link" << std::endl;
0062 auto sourceLinkConstruction = Acts::Test::microBenchmark(
0063 [&]() {
0064 SourceLink sl{bsl};
0065 return sl;
0066 },
0067 n);
0068 std::cout << " " << sourceLinkConstruction << std::endl;
0069
0070 std::vector<SourceLink> inputs;
0071 inputs.reserve(n);
0072 for (std::size_t i = 0; i < n; ++i) {
0073 inputs.emplace_back(bsl);
0074 }
0075
0076 std::cout << "Copy construct source link" << std::endl;
0077 auto copyConstructSourceLink = Acts::Test::microBenchmark(
0078 [&](const SourceLink& input) {
0079 SourceLink copy{input};
0080 return copy;
0081 },
0082 inputs);
0083 std::cout << copyConstructSourceLink << std::endl;
0084
0085 std::cout << "Copy then move construct source link" << std::endl;
0086 auto copyMoveConstructSourceLink = Acts::Test::microBenchmark(
0087 [&](const SourceLink& input) {
0088 SourceLink copy{input};
0089 SourceLink mv{std::move(copy)};
0090 return mv;
0091 },
0092 inputs);
0093 std::cout << copyMoveConstructSourceLink << std::endl;
0094
0095 std::cout << "Optional assignment" << std::endl;
0096 auto opt_assignment = Acts::Test::microBenchmark(
0097 [&]() {
0098 SourceLink sl{bsl};
0099
0100 std::optional<SourceLink> opt;
0101 opt = std::move(sl);
0102 return opt;
0103 },
0104 n);
0105 std::cout << opt_assignment << std::endl;
0106
0107
0108 std::cout << "Create track state" << std::endl;
0109 auto create_track_state = Acts::Test::microBenchmark(
0110 [&]() {
0111 auto ts = mtj.makeTrackState(TrackStatePropMask::None);
0112 return ts;
0113 },
0114 n / 10);
0115 std::cout << create_track_state << std::endl;
0116
0117 std::cout << "Assign source link to track state" << std::endl;
0118 auto assignSourceLink = Acts::Test::microBenchmark(
0119 [&]() {
0120 SourceLink sl{bsl};
0121 auto ts = mtj.makeTrackState(TrackStatePropMask::None);
0122 ts.setUncalibratedSourceLink(std::move(sl));
0123 return ts;
0124 },
0125 n / 10);
0126 std::cout << assignSourceLink << std::endl;
0127
0128 return 0;
0129 }