44
55#include < cstdlib>
66#include < filesystem>
7+ #include < numbers>
78
89namespace cppfig ::bench {
910
@@ -24,7 +25,7 @@ namespace settings {
2425 struct DoubleSetting {
2526 static constexpr std::string_view path = " benchmark.double" ;
2627 using value_type = double ;
27- static auto default_value () -> double { return 3.14159 ; }
28+ static auto default_value () -> double { return std::numbers::pi ; }
2829 };
2930
3031 struct BoolSetting {
@@ -119,7 +120,7 @@ class BenchmarkFixture : public ::benchmark::Fixture {
119120 return temp_path.string ();
120121 }
121122
122- void RemoveFile (const std::string& path)
123+ static void RemoveFile (const std::string& path)
123124 {
124125 if (std::filesystem::exists (path)) {
125126 std::filesystem::remove (path);
@@ -129,7 +130,7 @@ class BenchmarkFixture : public ::benchmark::Fixture {
129130
130131BENCHMARK_DEFINE_F (BenchmarkFixture, GetString)(benchmark::State& state)
131132{
132- std::string path = CreateTempFile ();
133+ const std::string path = CreateTempFile ();
133134 Configuration<SmallSchema> config (path);
134135 (void )config.Load ();
135136
@@ -144,7 +145,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, GetString);
144145
145146BENCHMARK_DEFINE_F (BenchmarkFixture, GetInt)(benchmark::State& state)
146147{
147- std::string path = CreateTempFile ();
148+ const std::string path = CreateTempFile ();
148149 Configuration<MediumSchema> config (path);
149150 (void )config.Load ();
150151
@@ -159,7 +160,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, GetInt);
159160
160161BENCHMARK_DEFINE_F (BenchmarkFixture, GetDouble)(benchmark::State& state)
161162{
162- std::string path = CreateTempFile ();
163+ const std::string path = CreateTempFile ();
163164 Configuration<MediumSchema> config (path);
164165 (void )config.Load ();
165166
@@ -174,7 +175,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, GetDouble);
174175
175176BENCHMARK_DEFINE_F (BenchmarkFixture, GetBool)(benchmark::State& state)
176177{
177- std::string path = CreateTempFile ();
178+ const std::string path = CreateTempFile ();
178179 Configuration<MediumSchema> config (path);
179180 (void )config.Load ();
180181
@@ -189,7 +190,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, GetBool);
189190
190191BENCHMARK_DEFINE_F (BenchmarkFixture, GetValidated)(benchmark::State& state)
191192{
192- std::string path = CreateTempFile ();
193+ const std::string path = CreateTempFile ();
193194 Configuration<MediumSchema> config (path);
194195 (void )config.Load ();
195196
@@ -204,13 +205,13 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, GetValidated);
204205
205206BENCHMARK_DEFINE_F (BenchmarkFixture, SetString)(benchmark::State& state)
206207{
207- std::string path = CreateTempFile ();
208+ const std::string path = CreateTempFile ();
208209 Configuration<SmallSchema> config (path);
209210 (void )config.Load ();
210211
211212 int counter = 0 ;
212213 for (auto _ : state) {
213- std::string value = " value_" + std::to_string (counter++);
214+ const std::string value = " value_" + std::to_string (counter++);
214215 auto status = config.Set <settings::StringSetting>(value);
215216 benchmark::DoNotOptimize (status);
216217 }
@@ -221,7 +222,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, SetString);
221222
222223BENCHMARK_DEFINE_F (BenchmarkFixture, SetInt)(benchmark::State& state)
223224{
224- std::string path = CreateTempFile ();
225+ const std::string path = CreateTempFile ();
225226 Configuration<MediumSchema> config (path);
226227 (void )config.Load ();
227228
@@ -237,7 +238,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, SetInt);
237238
238239BENCHMARK_DEFINE_F (BenchmarkFixture, SetValidated)(benchmark::State& state)
239240{
240- std::string path = CreateTempFile ();
241+ const std::string path = CreateTempFile ();
241242 Configuration<MediumSchema> config (path);
242243 (void )config.Load ();
243244
@@ -252,7 +253,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, SetValidated);
252253
253254BENCHMARK_DEFINE_F (BenchmarkFixture, LoadSmallSchema)(benchmark::State& state)
254255{
255- std::string path = CreateTempFile ();
256+ const std::string path = CreateTempFile ();
256257
257258 // Create initial file
258259 {
@@ -273,7 +274,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, LoadSmallSchema);
273274
274275BENCHMARK_DEFINE_F (BenchmarkFixture, LoadMediumSchema)(benchmark::State& state)
275276{
276- std::string path = CreateTempFile ();
277+ const std::string path = CreateTempFile ();
277278
278279 // Create initial file
279280 {
@@ -294,7 +295,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, LoadMediumSchema);
294295
295296BENCHMARK_DEFINE_F (BenchmarkFixture, LoadLargeSchema)(benchmark::State& state)
296297{
297- std::string path = CreateTempFile ();
298+ const std::string path = CreateTempFile ();
298299
299300 // Create initial file
300301 {
@@ -315,7 +316,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, LoadLargeSchema);
315316
316317BENCHMARK_DEFINE_F (BenchmarkFixture, SaveSmallSchema)(benchmark::State& state)
317318{
318- std::string path = CreateTempFile ();
319+ const std::string path = CreateTempFile ();
319320 Configuration<SmallSchema> config (path);
320321 (void )config.Load ();
321322
@@ -330,7 +331,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, SaveSmallSchema);
330331
331332BENCHMARK_DEFINE_F (BenchmarkFixture, SaveMediumSchema)(benchmark::State& state)
332333{
333- std::string path = CreateTempFile ();
334+ const std::string path = CreateTempFile ();
334335 Configuration<MediumSchema> config (path);
335336 (void )config.Load ();
336337
@@ -345,7 +346,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, SaveMediumSchema);
345346
346347BENCHMARK_DEFINE_F (BenchmarkFixture, SaveLargeSchema)(benchmark::State& state)
347348{
348- std::string path = CreateTempFile ();
349+ const std::string path = CreateTempFile ();
349350 Configuration<LargeSchema> config (path);
350351 (void )config.Load ();
351352
@@ -372,7 +373,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, ValidatorRange);
372373BENCHMARK_DEFINE_F (BenchmarkFixture, ValidatorNotEmpty)(benchmark::State& state)
373374{
374375 auto not_empty_validator = cppfig::NotEmpty ();
375- std::string test_value = " test" ;
376+ const std::string test_value = " test" ;
376377
377378 for (auto _ : state) {
378379 auto result = not_empty_validator (test_value);
@@ -405,7 +406,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, ValidatorCombined);
405406
406407BENCHMARK_DEFINE_F (BenchmarkFixture, DiffNoChanges)(benchmark::State& state)
407408{
408- std::string path = CreateTempFile ();
409+ const std::string path = CreateTempFile ();
409410 Configuration<MediumSchema> config (path);
410411 (void )config.Load ();
411412
@@ -420,7 +421,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, DiffNoChanges);
420421
421422BENCHMARK_DEFINE_F (BenchmarkFixture, DiffWithChanges)(benchmark::State& state)
422423{
423- std::string path = CreateTempFile ();
424+ const std::string path = CreateTempFile ();
424425 Configuration<MediumSchema> config (path);
425426 (void )config.Load ();
426427
@@ -439,7 +440,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, DiffWithChanges);
439440
440441BENCHMARK_DEFINE_F (BenchmarkFixture, JsonSerializerParse)(benchmark::State& state)
441442{
442- std::string json_str = R"( {
443+ const std::string json_str = R"( {
443444 "benchmark": {
444445 "string": "test",
445446 "int": 42,
@@ -462,7 +463,7 @@ BENCHMARK_DEFINE_F(BenchmarkFixture, JsonSerializerStringify)(benchmark::State&
462463 auto benchmark_obj = Value::Object ();
463464 benchmark_obj[" string" ] = Value (" test" );
464465 benchmark_obj[" int" ] = Value (42 );
465- benchmark_obj[" double" ] = Value (3.14159 );
466+ benchmark_obj[" double" ] = Value (std::numbers::pi );
466467 benchmark_obj[" bool" ] = Value (true );
467468 benchmark_obj[" validated" ] = Value (50 );
468469 value[" benchmark" ] = benchmark_obj;
@@ -483,7 +484,7 @@ BENCHMARK_DEFINE_F(BenchmarkFixture, ValueGetAtPath)(benchmark::State& state)
483484 connection[" port" ] = Value (5432 );
484485 database[" connection" ] = connection;
485486 value[" database" ] = database;
486- std::string path = " database.connection.host" ;
487+ const std::string path = " database.connection.host" ;
487488
488489 for (auto _ : state) {
489490 auto result = value.GetAtPath (path);
@@ -501,7 +502,7 @@ BENCHMARK_DEFINE_F(BenchmarkFixture, ValueSetAtPath)(benchmark::State& state)
501502 connection[" port" ] = Value (5432 );
502503 database[" connection" ] = connection;
503504 value[" database" ] = database;
504- std::string path = " database.connection.host" ;
505+ const std::string path = " database.connection.host" ;
505506
506507 for (auto _ : state) {
507508 Value value_copy = value;
@@ -522,7 +523,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, TraitsSerializeInt);
522523
523524BENCHMARK_DEFINE_F (BenchmarkFixture, TraitsDeserializeInt)(benchmark::State& state)
524525{
525- Value val (42 );
526+ const Value val (42 );
526527
527528 for (auto _ : state) {
528529 auto result = ConfigTraits<int >::Deserialize (val);
@@ -533,7 +534,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, TraitsDeserializeInt);
533534
534535BENCHMARK_DEFINE_F (BenchmarkFixture, TraitsSerializeString)(benchmark::State& state)
535536{
536- std::string value = " benchmark_test_string" ;
537+ const std::string value = " benchmark_test_string" ;
537538
538539 for (auto _ : state) {
539540 auto val = ConfigTraits<std::string>::Serialize (value);
@@ -544,7 +545,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, TraitsSerializeString);
544545
545546BENCHMARK_DEFINE_F (BenchmarkFixture, TraitsDeserializeString)(benchmark::State& state)
546547{
547- Value val (" benchmark_test_string" );
548+ const Value val (" benchmark_test_string" );
548549
549550 for (auto _ : state) {
550551 auto result = ConfigTraits<std::string>::Deserialize (val);
0 commit comments