1#include "benchmark_runner.hpp"
2#include "duckdb_benchmark_macro.hpp"
3#include "duckdb/main/appender.hpp"
4
5#include <random>
6
7using namespace duckdb;
8using namespace std;
9
10#define WINDOW_ROW_COUNT 100000
11
12DUCKDB_BENCHMARK(Window, "[micro]")
13virtual 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);");
20 Appender appender(state->conn, "integers"); // insert the elements into the database
21 for (size_t i = 0; i < WINDOW_ROW_COUNT; i++) {
22 appender.BeginRow();
23 appender.Append<int32_t>(distribution(gen));
24 appender.EndRow();
25 }
26}
27
28virtual string GetQuery() {
29 return "SELECT SUM(i) OVER(order by i rows between 1000 preceding and 1000 following) FROM integers";
30}
31
32virtual string VerifyResult(QueryResult *result) {
33 if (!result->success) {
34 return result->error;
35 }
36 auto &materialized = (MaterializedQueryResult &)*result;
37 if (materialized.collection.count != WINDOW_ROW_COUNT) {
38 return "Incorrect amount of rows in result";
39 }
40 return string();
41}
42
43virtual string BenchmarkInfo() {
44 return StringUtil::Format("Runs the following query: \"%s\""
45 " on %d rows",
46 GetQuery().c_str(), WINDOW_ROW_COUNT);
47}
48FINISH_BENCHMARK(Window)
49