@@ -14,9 +14,9 @@ boost::filesystem::path tempFolder(const std::string& subfolder)
1414 return temp;
1515}
1616
17- static void BM_DBCreateOpen (benchmark::State& state)
17+ static void DBCreateOpen (benchmark::State& state)
1818{
19- auto tempfolder = (tempFolder (" BM_DBCreateOpen " )).string ();
19+ auto tempfolder = (tempFolder (" DBCreateOpen " )).string ();
2020
2121 ashdb::Options options;
2222 options.create_if_missing = true ;
@@ -28,11 +28,11 @@ static void BM_DBCreateOpen(benchmark::State& state)
2828 db.open ();
2929 }
3030}
31- BENCHMARK (BM_DBCreateOpen );
31+ BENCHMARK (DBCreateOpen );
3232
33- static void BM_DBOpenClose (benchmark::State& state)
33+ static void DBOpenClose (benchmark::State& state)
3434{
35- auto tempfolder = (tempFolder (" BM_DBOpenClose " )).string ();
35+ auto tempfolder = (tempFolder (" DBOpenClose " )).string ();
3636
3737 ashdb::Options options;
3838 options.create_if_missing = true ;
@@ -46,11 +46,11 @@ static void BM_DBOpenClose(benchmark::State& state)
4646 db.close ();
4747 }
4848}
49- BENCHMARK (BM_DBOpenClose );
49+ BENCHMARK (DBOpenClose );
5050
51- static void BM_DBWriteInt (benchmark::State& state)
51+ static void DBWriteInt (benchmark::State& state)
5252{
53- auto tempfolder = (tempFolder (" BM_DBWriteInt " )).string ();
53+ auto tempfolder = (tempFolder (" DBWriteInt " )).string ();
5454
5555 ashdb::Options options;
5656 options.create_if_missing = true ;
@@ -63,11 +63,11 @@ static void BM_DBWriteInt(benchmark::State& state)
6363 db.write (3 );
6464 }
6565}
66- BENCHMARK (BM_DBWriteInt );
66+ BENCHMARK (DBWriteInt );
6767
68- static void BM_DBMultipleIntWrites (benchmark::State& state)
68+ static void DBMultipleIntWrites (benchmark::State& state)
6969{
70- auto tempfolder = (tempFolder (" BM_DBMultipleIntWrites " )).string ();
70+ auto tempfolder = (tempFolder (" DBMultipleIntWrites " )).string ();
7171
7272 ashdb::Options options;
7373 options.create_if_missing = true ;
@@ -83,11 +83,11 @@ static void BM_DBMultipleIntWrites(benchmark::State& state)
8383 }
8484 }
8585}
86- BENCHMARK (BM_DBMultipleIntWrites );
86+ BENCHMARK (DBMultipleIntWrites );
8787
88- static void BM_DBRandomIntReads (benchmark::State& state)
88+ static void DBRandomIntReads (benchmark::State& state)
8989{
90- auto tempfolder = (tempFolder (" BM_DBRandomIntReads " )).string ();
90+ auto tempfolder = (tempFolder (" DBRandomIntReads " )).string ();
9191
9292 std::random_device rd;
9393 std::mt19937 gen (rd ());
@@ -115,13 +115,13 @@ static void BM_DBRandomIntReads(benchmark::State& state)
115115 }
116116 }
117117}
118- BENCHMARK (BM_DBRandomIntReads );
118+ BENCHMARK (DBRandomIntReads );
119119
120- #include " ../tests/test_class1 .h"
120+ #include " ../tests/Person .h"
121121
122- static void BM_DBWriteStruct (benchmark::State& state)
122+ static void DBWriteStruct (benchmark::State& state)
123123{
124- auto tempfolder = (tempFolder (" BM_DBWriteStruct " )).string ();
124+ auto tempfolder = (tempFolder (" DBWriteStruct " )).string ();
125125
126126 ashdb::Options options;
127127 options.create_if_missing = true ;
@@ -143,11 +143,11 @@ static void BM_DBWriteStruct(benchmark::State& state)
143143 db.write (p);
144144 }
145145}
146- BENCHMARK (BM_DBWriteStruct );
146+ BENCHMARK (DBWriteStruct );
147147
148- static void BM_DBMultipleStructWrites (benchmark::State& state)
148+ static void DBMultipleStructWrites (benchmark::State& state)
149149{
150- auto tempfolder = (tempFolder (" BM_DBStructMultipleWrites " )).string ();
150+ auto tempfolder = (tempFolder (" DBStructMultipleWrites " )).string ();
151151
152152 ashdb::Options options;
153153 options.create_if_missing = true ;
@@ -174,11 +174,11 @@ static void BM_DBMultipleStructWrites(benchmark::State& state)
174174 }
175175 }
176176}
177- BENCHMARK (BM_DBMultipleStructWrites );
177+ BENCHMARK (DBMultipleStructWrites );
178178
179- static void BM_DBRandomStructReads (benchmark::State& state)
179+ static void DBRandomStructReads (benchmark::State& state)
180180{
181- auto tempfolder = (tempFolder (" BM_DBRandomIntReads " )).string ();
181+ auto tempfolder = (tempFolder (" DBRandomIntReads " )).string ();
182182
183183 std::random_device rd;
184184 std::mt19937 gen (rd ());
@@ -215,6 +215,86 @@ static void BM_DBRandomStructReads(benchmark::State& state)
215215 }
216216 }
217217}
218- BENCHMARK (BM_DBRandomStructReads);
218+ BENCHMARK (DBRandomStructReads);
219+
220+ // comparison with "DBMultipleStructWrites"
221+ static void BatchWriteMultipleFiles (benchmark::State& state)
222+ {
223+ auto tempfolder = (tempFolder (" DBStructMultipleWrites" )).string ();
224+
225+ ashdb::Options options;
226+ options.create_if_missing = true ;
227+ options.error_if_exists = false ;
228+
229+ ashdb::AshDB<project::Person> db{ tempfolder, options };
230+ db.open ();
231+
232+ while (state.KeepRunning ())
233+ {
234+ project::PersonDB::Batch batch;
235+ for (auto i = 0u ; i < 100 ; ++i)
236+ {
237+ state.PauseTiming ();
238+ project::Person p;
239+ p.name .first = " Firstname" + std::to_string (i);
240+ p.name .middle = (i % 2 ) ? " Middle" + std::to_string (i) : " " ;
241+ p.name .last = " Lastname" + std::to_string (i);
242+ p.age = (i % 80 );
243+ p.salary = (i % 5 ) * 12345.67 ;
244+ p.married = (i % 2 ) == 0 ;
245+ batch.push_back (p);
246+ state.ResumeTiming ();
247+ }
248+
249+ db.write (batch);
250+ }
251+ }
252+ BENCHMARK (BatchWriteMultipleFiles);
253+
254+ // compare to "DBRandomStructReads"
255+ static void BatchReadMultipleFiles (benchmark::State& state)
256+ {
257+ auto tempfolder = (tempFolder (" BatchReadMultipleFiles" )).string ();
258+
259+ ashdb::Options options;
260+ options.filesize_max = 100 ;
261+
262+ ashdb::AshDB<project::Person> db{ tempfolder, options };
263+ db.open ();
264+
265+ project::PersonDB::Batch batch;
266+ for (auto i = 0u ; i < 200 ; ++i)
267+ {
268+ project::Person p;
269+ p.name .first = " Firstname" + std::to_string (i);
270+ p.name .middle = (i % 2 ) ? " Middle" + std::to_string (i) : " " ;
271+ p.name .last = " Lastname" + std::to_string (i);
272+ p.age = (i % 80 );
273+ p.salary = (i % 5 ) * 12345.67 ;
274+ p.married = (i % 2 ) == 0 ;
275+
276+ batch.push_back (p);
277+ }
278+ db.write (batch);
279+
280+ std::random_device rd;
281+ std::mt19937 gen (rd ());
282+
283+ while (state.KeepRunning ())
284+ {
285+ state.PauseTiming ();
286+ std::uniform_int_distribution<> distrib (0 , 99 );
287+ std::uint32_t idx = static_cast <std::uint32_t >(distrib (gen));
288+ state.ResumeTiming ();
289+
290+ // read 100 records at a random idx
291+ auto b = db.read (idx, 100 );
292+
293+ state.PauseTiming ();
294+ b.clear (); // do something to avoid unused var warning
295+ state.ResumeTiming ();
296+ }
297+ }
298+ BENCHMARK (BatchReadMultipleFiles);
219299
220300BENCHMARK_MAIN ();
0 commit comments