1515// /
1616
1717#include < TH1.h>
18+ #include < boost/container/flat_map.hpp>
1819#include < catch_amalgamated.hpp>
1920#include " Framework/include/QualityControl/MonitorObject.h"
2021#include " QualityControl/Data.h"
2122#include " QualityControl/DataAdapters.h"
2223#include < cstring>
23- #include < iostream>
2424#include < memory>
25+ #include < string>
2526
2627using namespace o2 ::quality_control::core;
2728
@@ -41,7 +42,7 @@ TEST_CASE("Data insert and get", "[Data]")
4142 REQUIRE (!valueStr.has_value ());
4243 auto valueInt = data.get <int >(" test" );
4344 REQUIRE (valueInt.has_value ());
44- REQUIRE (valueInt. value () == 1 );
45+ REQUIRE (valueInt == 1 );
4546}
4647
4748TEST_CASE (" Data - iterateByType" , " [Data]" )
@@ -183,3 +184,101 @@ TEST_CASE("Data - raw pointers", "[Data]")
183184 }
184185 REQUIRE (count == 2 );
185186}
187+
188+ using stdmap = std::map<std::string, std::any, std::less<>>;
189+ using boostflatmap = boost::container::flat_map<std::string, std::any, std::less<>>;
190+
191+ TEMPLATE_TEST_CASE (" Data - inserting fundamental types" , " [.Data-benchmark]" , stdmap, boostflatmap, transparent_unordered_map)
192+ {
193+ constexpr size_t iterations = 20'000 ;
194+
195+ BENCHMARK (" insert size_t" )
196+ {
197+ DataGeneric<TestType> data;
198+ // for (size_t i = 0; i != iterations; ++i) {
199+ for (size_t i = iterations; i != 0 ; --i) {
200+ data.insert (std::to_string (i), i);
201+ }
202+ };
203+ }
204+
205+ TEMPLATE_TEST_CASE (" Data - iterating fundamental types" , " [Data-benchmark]" , stdmap, boostflatmap, transparent_unordered_map)
206+ {
207+ constexpr size_t iterations = 20000 ;
208+ DataGeneric<TestType> data;
209+ for (size_t i = 0 ; i != iterations; ++i) {
210+ data.insert (std::to_string (i), i);
211+ }
212+
213+ REQUIRE (data.size () == iterations);
214+ BENCHMARK (" iterate size_t" )
215+ {
216+ REQUIRE (data.size () == iterations);
217+ size_t r{};
218+ size_t count{};
219+ for (const auto & v : data.template iterateByType <size_t >()) {
220+ r += v;
221+ count++;
222+ }
223+ REQUIRE (count == iterations);
224+ };
225+ }
226+
227+ TEMPLATE_TEST_CASE (" Data - get fundamental types" , " [.Data-benchmark]" , stdmap, boostflatmap, transparent_unordered_map)
228+ {
229+ constexpr size_t iterations = 20000 ;
230+ DataGeneric<TestType> data;
231+ for (size_t i = 0 ; i != iterations; ++i) {
232+ data.insert (std::to_string (i), i);
233+ }
234+
235+ REQUIRE (data.size () == iterations);
236+ BENCHMARK (" iterate size_t" )
237+ {
238+ size_t r{};
239+ size_t count{};
240+ for (size_t i = 0 ; i != iterations; ++i) {
241+ auto opt = data.template get <size_t >(std::to_string (i));
242+ r += opt.value ();
243+ count++;
244+ }
245+ REQUIRE (count == iterations);
246+ };
247+ }
248+
249+ std::string generateRandomString (size_t length)
250+ {
251+ static constexpr std::string_view CHARACTERS = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ;
252+ thread_local std::mt19937 generator (std::random_device{}());
253+ std::uniform_int_distribution<size_t > distribution (0 , CHARACTERS .length () - 1 );
254+
255+ std::string random_string;
256+ random_string.reserve (length);
257+ for (size_t i = 0 ; i < length; ++i) {
258+ random_string += CHARACTERS [distribution (generator)];
259+ }
260+ return random_string;
261+ }
262+
263+ TEMPLATE_TEST_CASE (" Data - inserting and iterating MOs" , " [.Data-benchmark]" , stdmap, boostflatmap, transparent_unordered_map)
264+ {
265+ constexpr size_t iterations = 1000 ;
266+ std::vector<std::shared_ptr<MonitorObject>> MOs;
267+
268+ for (size_t i = 0 ; i != iterations; ++i) {
269+ const auto name = generateRandomString (20 );
270+ auto * h = new TH1F (name.c_str (), name.c_str (), 100 , 0 , 99 );
271+ std::shared_ptr<MonitorObject> mo = std::make_shared<MonitorObject>(h, " taskname" , " class1" , " TST" );
272+ MOs.push_back (mo);
273+ }
274+
275+ BENCHMARK (" insert - iterate MOs" )
276+ {
277+ DataGeneric<TestType> data;
278+ for (const auto & mo : MOs) {
279+ data.insert (mo->getFullName (), mo);
280+ }
281+
282+ REQUIRE (iterateMOsFilterByNameAndTransform<TH1F >(data, " notimportantname" ).empty ());
283+ };
284+ }
0 commit comments