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 IN_LIST_ROW_COUNT 1000000
11#define STRING_LENGTH 4
12
13#define IN_QUERY_BODY(INCOUNT, NOT_IN) \
14 static constexpr const char *chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; \
15 string in_list; \
16 static string GenerateString(std::uniform_int_distribution<> &distribution, std::mt19937 &gen) { \
17 string result; \
18 for (size_t i = 0; i < STRING_LENGTH; i++) { \
19 result += string(1, chars[distribution(gen)]); \
20 } \
21 return result; \
22 } \
23 virtual void Load(DuckDBBenchmarkState *state) { \
24 std::uniform_int_distribution<> distribution(0, strlen(chars) - 1); \
25 std::mt19937 gen; \
26 gen.seed(42); \
27 state->conn.Query("CREATE TABLE strings(s VARCHAR);"); \
28 Appender appender(state->conn, "strings"); \
29 for (size_t i = 0; i < IN_LIST_ROW_COUNT; i++) { \
30 appender.BeginRow(); \
31 appender.Append<Value>(Value(GenerateString(distribution, gen))); \
32 appender.EndRow(); \
33 } \
34 appender.Close(); \
35 for (size_t i = 0; i < INCOUNT; i++) { \
36 in_list += "'" + GenerateString(distribution, gen) + "'"; \
37 if (i != INCOUNT - 1) { \
38 in_list += ", "; \
39 } \
40 } \
41 } \
42 virtual string GetQuery() { \
43 return "SELECT * FROM strings WHERE s " + (NOT_IN ? string("NOT ") : string("")) + "IN (" + in_list + ")"; \
44 } \
45 virtual string VerifyResult(QueryResult *result) { \
46 if (!result->success) { \
47 return result->error; \
48 } \
49 return string(); \
50 } \
51 virtual string BenchmarkInfo() { \
52 return StringUtil::Format("Runs the following query: \"" + GetQuery() + "\""); \
53 }
54
55DUCKDB_BENCHMARK(InList0001Entry, "[in]")
56IN_QUERY_BODY(1, false)
57FINISH_BENCHMARK(InList0001Entry)
58
59DUCKDB_BENCHMARK(InList0002Entry, "[in]")
60IN_QUERY_BODY(2, false)
61FINISH_BENCHMARK(InList0002Entry)
62
63DUCKDB_BENCHMARK(InList0004Entry, "[in]")
64IN_QUERY_BODY(4, false)
65FINISH_BENCHMARK(InList0004Entry)
66
67DUCKDB_BENCHMARK(InList0008Entry, "[in]")
68IN_QUERY_BODY(8, false)
69FINISH_BENCHMARK(InList0008Entry)
70
71DUCKDB_BENCHMARK(InList0016Entry, "[in]")
72IN_QUERY_BODY(16, false)
73FINISH_BENCHMARK(InList0016Entry)
74
75DUCKDB_BENCHMARK(InList0032Entry, "[in]")
76IN_QUERY_BODY(32, false)
77FINISH_BENCHMARK(InList0032Entry)
78
79DUCKDB_BENCHMARK(InList0064Entry, "[in]")
80IN_QUERY_BODY(64, false)
81FINISH_BENCHMARK(InList0064Entry)
82
83DUCKDB_BENCHMARK(InList0128Entry, "[in]")
84IN_QUERY_BODY(128, false)
85FINISH_BENCHMARK(InList0128Entry)
86
87DUCKDB_BENCHMARK(InList0256Entry, "[in]")
88IN_QUERY_BODY(256, false)
89FINISH_BENCHMARK(InList0256Entry)
90
91DUCKDB_BENCHMARK(InList0512Entry, "[in]")
92IN_QUERY_BODY(512, false)
93FINISH_BENCHMARK(InList0512Entry)
94
95DUCKDB_BENCHMARK(InList1024Entry, "[in]")
96IN_QUERY_BODY(1024, false)
97FINISH_BENCHMARK(InList1024Entry)
98
99DUCKDB_BENCHMARK(InList2048Entry, "[in]")
100IN_QUERY_BODY(2048, false)
101FINISH_BENCHMARK(InList2048Entry)
102
103DUCKDB_BENCHMARK(NotInList0001Entry, "[in]")
104IN_QUERY_BODY(1, true)
105FINISH_BENCHMARK(NotInList0001Entry)
106
107DUCKDB_BENCHMARK(NotInList0002Entry, "[in]")
108IN_QUERY_BODY(2, true)
109FINISH_BENCHMARK(NotInList0002Entry)
110
111DUCKDB_BENCHMARK(NotInList0004Entry, "[in]")
112IN_QUERY_BODY(4, true)
113FINISH_BENCHMARK(NotInList0004Entry)
114
115DUCKDB_BENCHMARK(NotInList0008Entry, "[in]")
116IN_QUERY_BODY(8, true)
117FINISH_BENCHMARK(NotInList0008Entry)
118
119DUCKDB_BENCHMARK(NotInList0016Entry, "[in]")
120IN_QUERY_BODY(16, true)
121FINISH_BENCHMARK(NotInList0016Entry)
122
123DUCKDB_BENCHMARK(NotInList0032Entry, "[in]")
124IN_QUERY_BODY(32, true)
125FINISH_BENCHMARK(NotInList0032Entry)
126
127DUCKDB_BENCHMARK(NotInList0064Entry, "[in]")
128IN_QUERY_BODY(64, true)
129FINISH_BENCHMARK(NotInList0064Entry)
130
131DUCKDB_BENCHMARK(NotInList0128Entry, "[in]")
132IN_QUERY_BODY(128, true)
133FINISH_BENCHMARK(NotInList0128Entry)
134
135DUCKDB_BENCHMARK(NotInList0256Entry, "[in]")
136IN_QUERY_BODY(256, true)
137FINISH_BENCHMARK(NotInList0256Entry)
138
139DUCKDB_BENCHMARK(NotInList0512Entry, "[in]")
140IN_QUERY_BODY(512, true)
141FINISH_BENCHMARK(NotInList0512Entry)
142
143DUCKDB_BENCHMARK(NotInList1024Entry, "[in]")
144IN_QUERY_BODY(1024, true)
145FINISH_BENCHMARK(NotInList1024Entry)
146
147DUCKDB_BENCHMARK(NotInList2048Entry, "[in]")
148IN_QUERY_BODY(2048, true)
149FINISH_BENCHMARK(NotInList2048Entry)
150