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