1+ #include " dsf/mobility/Agent.hpp"
2+
3+ #include < benchmark/benchmark.h>
4+ #include < memory>
5+
6+ static void BM_Agent_ConstructionWithItineraryId (benchmark::State& state) {
7+ std::time_t spawnTime = 0 ;
8+ for (auto _ : state) {
9+ dsf::mobility::Agent agent (spawnTime++, 1 , 0 );
10+ benchmark::DoNotOptimize (agent);
11+ }
12+ }
13+
14+ static void BM_Agent_ConstructionWithTrip (benchmark::State& state) {
15+ std::time_t spawnTime = 0 ;
16+ std::vector<dsf::Id> trip = {1 , 2 , 3 };
17+ for (auto _ : state) {
18+ dsf::mobility::Agent agent (spawnTime++, trip, 0 );
19+ benchmark::DoNotOptimize (agent);
20+ }
21+ }
22+
23+ static void BM_Agent_ConstructionRandom (benchmark::State& state) {
24+ std::time_t spawnTime = 0 ;
25+ for (auto _ : state) {
26+ dsf::mobility::Agent agent (spawnTime++);
27+ benchmark::DoNotOptimize (agent);
28+ }
29+ }
30+
31+ static void BM_Agent_SetSrcNodeId (benchmark::State& state) {
32+ dsf::mobility::Agent agent (0 , 1 , 0 );
33+ for (auto _ : state) {
34+ agent.setSrcNodeId (5 );
35+ }
36+ }
37+
38+ static void BM_Agent_SetStreetId (benchmark::State& state) {
39+ dsf::mobility::Agent agent (0 , 1 , 0 );
40+ for (auto _ : state) {
41+ agent.setStreetId (10 );
42+ }
43+ }
44+
45+ static void BM_Agent_SetNextStreetId (benchmark::State& state) {
46+ dsf::mobility::Agent agent (0 , 1 , 0 );
47+ for (auto _ : state) {
48+ agent.setNextStreetId (15 );
49+ }
50+ }
51+
52+ static void BM_Agent_SetSpeed (benchmark::State& state) {
53+ dsf::mobility::Agent agent (0 , 1 , 0 );
54+ for (auto _ : state) {
55+ agent.setSpeed (50.0 );
56+ }
57+ }
58+
59+ static void BM_Agent_SetFreeTime (benchmark::State& state) {
60+ dsf::mobility::Agent agent (0 , 1 , 0 );
61+ std::time_t freeTime = 100 ;
62+ for (auto _ : state) {
63+ agent.setFreeTime (freeTime++);
64+ }
65+ }
66+
67+ static void BM_Agent_IncrementDistance (benchmark::State& state) {
68+ dsf::mobility::Agent agent (0 , 1 , 0 );
69+ for (auto _ : state) {
70+ agent.incrementDistance (10.0 );
71+ }
72+ }
73+
74+ static void BM_Agent_UpdateItinerary (benchmark::State& state) {
75+ std::vector<dsf::Id> trip = {1 , 2 , 3 , 4 , 5 };
76+ dsf::mobility::Agent agent (0 , trip, 0 );
77+ for (auto _ : state) {
78+ agent.updateItinerary ();
79+ }
80+ }
81+
82+ static void BM_Agent_Reset (benchmark::State& state) {
83+ dsf::mobility::Agent agent (0 , 1 , 0 );
84+ agent.setSpeed (50.0 );
85+ agent.setStreetId (10 );
86+ std::time_t spawnTime = 1000 ;
87+ for (auto _ : state) {
88+ agent.reset (spawnTime++);
89+ }
90+ }
91+
92+ // Getter benchmarks - these are inline so very fast
93+ static void BM_Agent_Getters (benchmark::State& state) {
94+ dsf::mobility::Agent agent (0 , 1 , 0 );
95+ agent.setSpeed (50.0 );
96+ agent.setStreetId (10 );
97+ for (auto _ : state) {
98+ auto spawnTime = agent.spawnTime ();
99+ auto freeTime = agent.freeTime ();
100+ auto id = agent.id ();
101+ auto streetId = agent.streetId ();
102+ auto srcNodeId = agent.srcNodeId ();
103+ auto nextStreetId = agent.nextStreetId ();
104+ auto speed = agent.speed ();
105+ auto distance = agent.distance ();
106+ auto isRandom = agent.isRandom ();
107+ benchmark::DoNotOptimize (spawnTime);
108+ benchmark::DoNotOptimize (freeTime);
109+ benchmark::DoNotOptimize (id);
110+ benchmark::DoNotOptimize (streetId);
111+ benchmark::DoNotOptimize (srcNodeId);
112+ benchmark::DoNotOptimize (nextStreetId);
113+ benchmark::DoNotOptimize (speed);
114+ benchmark::DoNotOptimize (distance);
115+ benchmark::DoNotOptimize (isRandom);
116+ }
117+ }
118+
119+ static void BM_Agent_ItineraryId (benchmark::State& state) {
120+ dsf::mobility::Agent agent (0 , 1 , 0 );
121+ for (auto _ : state) {
122+ auto itineraryId = agent.itineraryId ();
123+ benchmark::DoNotOptimize (itineraryId);
124+ }
125+ }
126+
127+ static void BM_Agent_Trip (benchmark::State& state) {
128+ dsf::mobility::Agent agent (0 , {1 , 2 , 3 }, 0 );
129+ for (auto _ : state) {
130+ auto trip = agent.trip ();
131+ benchmark::DoNotOptimize (trip);
132+ }
133+ }
134+
135+ BENCHMARK (BM_Agent_ConstructionWithItineraryId);
136+ BENCHMARK (BM_Agent_ConstructionWithTrip);
137+ BENCHMARK (BM_Agent_ConstructionRandom);
138+ BENCHMARK (BM_Agent_SetSrcNodeId);
139+ BENCHMARK (BM_Agent_SetStreetId);
140+ BENCHMARK (BM_Agent_SetNextStreetId);
141+ BENCHMARK (BM_Agent_SetSpeed);
142+ BENCHMARK (BM_Agent_SetFreeTime);
143+ BENCHMARK (BM_Agent_IncrementDistance);
144+ BENCHMARK (BM_Agent_UpdateItinerary);
145+ BENCHMARK (BM_Agent_Reset);
146+ BENCHMARK (BM_Agent_Getters);
147+ BENCHMARK (BM_Agent_ItineraryId);
148+ BENCHMARK (BM_Agent_Trip);
149+
150+ BENCHMARK_MAIN ();
0 commit comments