Skip to content

Commit dd6b9ce

Browse files
committed
Added a benchmark for DuckDB database write
1 parent 380ee77 commit dd6b9ce

4 files changed

Lines changed: 777 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
benchmark: benchmark.cc
2+
g++ -std=c++17 benchmark.cc -lduckdb -o benchmark -g
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include "ddb_wrapper.h"
2+
#include "pdb_schema.h"
3+
4+
void benchmark1(){
5+
//Test a simple table with float columns as we scale #rows and #cols
6+
Timer timer;
7+
8+
//Hot loop; row batches are all added to the same table. Table is *not* flushed to disk
9+
for(int c=1; c<101; c+=10){
10+
remove("database.ddb");
11+
12+
timer.start();
13+
duckdb_database db;
14+
duckdb_connection con;
15+
if (duckdb_open("database.ddb", &db) == DuckDBError) assert(0);
16+
if (duckdb_connect(db, &con) == DuckDBError) assert(0);
17+
18+
{ //disable checkpointing to disk
19+
assert(duckdb_query(con, "SET checkpoint_threshold = '100 GB';", NULL) != DuckDBError);
20+
//assert(duckdb_query(con, "SET checkpoint_threshold = '8 B';", NULL) != DuckDBError);
21+
}
22+
23+
Table table("mytable");
24+
//setup the table
25+
for(int cc=0;cc<c;cc++) table.addColumn<double>("col"+std::to_string(cc));
26+
//tell duckdb about our table
27+
table.define(con);
28+
double topen = timer.elapsed_us();
29+
30+
for(int rbatch_sz=10; rbatch_sz<100000; rbatch_sz*=2){
31+
table.resizeRows(rbatch_sz); //note that the table represents the unwritten portion here
32+
for(int r=0;r<rbatch_sz;r++)
33+
for(int cc=0;cc<c;cc++)
34+
table(r,cc) = cc+c*r+3.14;
35+
36+
for(int rpt=0;rpt<4;rpt++){
37+
timer.start();
38+
table.write(con);
39+
double twrite = timer.elapsed_us();
40+
41+
std::cout << "PRE COMMIT: " << table.databaseSize(con) << std::endl;
42+
43+
//assert(duckdb_query(con, "PRAGMA enable_profiling;", NULL) != DuckDBError);
44+
//assert(duckdb_query(con, "SET enable_profiling = 'query_tree';", NULL) != DuckDBError);
45+
//assert(duckdb_query(con, "SET profiling_mode = 'detailed';", NULL) != DuckDBError);
46+
timer.start();
47+
table.commit(con);
48+
double tcommit = timer.elapsed_us();
49+
//assert(duckdb_query(con, "PRAGMA disable_profiling;", NULL) != DuckDBError);
50+
51+
std::cout << "POST COMMIT: " << table.databaseSize(con) << std::endl;
52+
53+
std::cout << rbatch_sz << "," << c << " " << rbatch_sz * c << " : "
54+
<< "total append "<< twrite << "us commit " << tcommit << "us"
55+
<< ", per row append " << twrite/rbatch_sz << "us commit " << tcommit/rbatch_sz << "us"
56+
<< ", per elem append " << twrite/rbatch_sz/c << "us commit " << tcommit/rbatch_sz/c << "us"
57+
<< std::endl;
58+
}
59+
}
60+
61+
timer.start();
62+
duckdb_disconnect(&con);
63+
duckdb_close(&db);
64+
double tclose = timer.elapsed_us();
65+
}
66+
67+
68+
69+
}
70+
int main(void){
71+
benchmark1();
72+
return 0;
73+
}

0 commit comments

Comments
 (0)