1 | #include "benchmark_runner.hpp" |
---|---|
2 | #include "duckdb_benchmark_macro.hpp" |
3 | #include "duckdb/main/appender.hpp" |
4 | |
5 | #include <random> |
6 | |
7 | using namespace duckdb; |
8 | using namespace std; |
9 | |
10 | #define ORDER_BY_ROW_COUNT 100000 |
11 | |
12 | DUCKDB_BENCHMARK(OrderBySingleColumn, "[micro]") |
13 | virtual void Load(DuckDBBenchmarkState *state) { |
14 | // fixed seed random numbers |
15 | std::uniform_int_distribution<> distribution(1, 10000); |
16 | std::mt19937 gen; |
17 | gen.seed(42); |
18 | |
19 | state->conn.Query("CREATE TABLE integers(i INTEGER, j INTEGER);"); |
20 | Appender appender(state->conn, "integers"); // insert the elements into the database |
21 | for (size_t i = 0; i < ORDER_BY_ROW_COUNT; i++) { |
22 | appender.BeginRow(); |
23 | appender.Append<int32_t>(distribution(gen)); |
24 | appender.Append<int32_t>(distribution(gen)); |
25 | appender.EndRow(); |
26 | } |
27 | } |
28 | |
29 | virtual string GetQuery() { |
30 | return "SELECT * FROM integers ORDER BY i"; |
31 | } |
32 | |
33 | virtual string VerifyResult(QueryResult *result) { |
34 | if (!result->success) { |
35 | return result->error; |
36 | } |
37 | auto &materialized = (MaterializedQueryResult &)*result; |
38 | if (materialized.collection.count != ORDER_BY_ROW_COUNT) { |
39 | return "Incorrect amount of rows in result"; |
40 | } |
41 | return string(); |
42 | } |
43 | |
44 | virtual string BenchmarkInfo() { |
45 | return StringUtil::Format("Runs the following query: \"SELECT * FROM integers ORDER BY i\"" |
46 | " on %d rows", |
47 | ORDER_BY_ROW_COUNT); |
48 | } |
49 | FINISH_BENCHMARK(OrderBySingleColumn) |
50 |