| 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 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 |  | 
|---|
| 55 | DUCKDB_BENCHMARK(InList0001Entry, "[in]") | 
|---|
| 56 | IN_QUERY_BODY(1, false) | 
|---|
| 57 | FINISH_BENCHMARK(InList0001Entry) | 
|---|
| 58 |  | 
|---|
| 59 | DUCKDB_BENCHMARK(InList0002Entry, "[in]") | 
|---|
| 60 | IN_QUERY_BODY(2, false) | 
|---|
| 61 | FINISH_BENCHMARK(InList0002Entry) | 
|---|
| 62 |  | 
|---|
| 63 | DUCKDB_BENCHMARK(InList0004Entry, "[in]") | 
|---|
| 64 | IN_QUERY_BODY(4, false) | 
|---|
| 65 | FINISH_BENCHMARK(InList0004Entry) | 
|---|
| 66 |  | 
|---|
| 67 | DUCKDB_BENCHMARK(InList0008Entry, "[in]") | 
|---|
| 68 | IN_QUERY_BODY(8, false) | 
|---|
| 69 | FINISH_BENCHMARK(InList0008Entry) | 
|---|
| 70 |  | 
|---|
| 71 | DUCKDB_BENCHMARK(InList0016Entry, "[in]") | 
|---|
| 72 | IN_QUERY_BODY(16, false) | 
|---|
| 73 | FINISH_BENCHMARK(InList0016Entry) | 
|---|
| 74 |  | 
|---|
| 75 | DUCKDB_BENCHMARK(InList0032Entry, "[in]") | 
|---|
| 76 | IN_QUERY_BODY(32, false) | 
|---|
| 77 | FINISH_BENCHMARK(InList0032Entry) | 
|---|
| 78 |  | 
|---|
| 79 | DUCKDB_BENCHMARK(InList0064Entry, "[in]") | 
|---|
| 80 | IN_QUERY_BODY(64, false) | 
|---|
| 81 | FINISH_BENCHMARK(InList0064Entry) | 
|---|
| 82 |  | 
|---|
| 83 | DUCKDB_BENCHMARK(InList0128Entry, "[in]") | 
|---|
| 84 | IN_QUERY_BODY(128, false) | 
|---|
| 85 | FINISH_BENCHMARK(InList0128Entry) | 
|---|
| 86 |  | 
|---|
| 87 | DUCKDB_BENCHMARK(InList0256Entry, "[in]") | 
|---|
| 88 | IN_QUERY_BODY(256, false) | 
|---|
| 89 | FINISH_BENCHMARK(InList0256Entry) | 
|---|
| 90 |  | 
|---|
| 91 | DUCKDB_BENCHMARK(InList0512Entry, "[in]") | 
|---|
| 92 | IN_QUERY_BODY(512, false) | 
|---|
| 93 | FINISH_BENCHMARK(InList0512Entry) | 
|---|
| 94 |  | 
|---|
| 95 | DUCKDB_BENCHMARK(InList1024Entry, "[in]") | 
|---|
| 96 | IN_QUERY_BODY(1024, false) | 
|---|
| 97 | FINISH_BENCHMARK(InList1024Entry) | 
|---|
| 98 |  | 
|---|
| 99 | DUCKDB_BENCHMARK(InList2048Entry, "[in]") | 
|---|
| 100 | IN_QUERY_BODY(2048, false) | 
|---|
| 101 | FINISH_BENCHMARK(InList2048Entry) | 
|---|
| 102 |  | 
|---|
| 103 | DUCKDB_BENCHMARK(NotInList0001Entry, "[in]") | 
|---|
| 104 | IN_QUERY_BODY(1, true) | 
|---|
| 105 | FINISH_BENCHMARK(NotInList0001Entry) | 
|---|
| 106 |  | 
|---|
| 107 | DUCKDB_BENCHMARK(NotInList0002Entry, "[in]") | 
|---|
| 108 | IN_QUERY_BODY(2, true) | 
|---|
| 109 | FINISH_BENCHMARK(NotInList0002Entry) | 
|---|
| 110 |  | 
|---|
| 111 | DUCKDB_BENCHMARK(NotInList0004Entry, "[in]") | 
|---|
| 112 | IN_QUERY_BODY(4, true) | 
|---|
| 113 | FINISH_BENCHMARK(NotInList0004Entry) | 
|---|
| 114 |  | 
|---|
| 115 | DUCKDB_BENCHMARK(NotInList0008Entry, "[in]") | 
|---|
| 116 | IN_QUERY_BODY(8, true) | 
|---|
| 117 | FINISH_BENCHMARK(NotInList0008Entry) | 
|---|
| 118 |  | 
|---|
| 119 | DUCKDB_BENCHMARK(NotInList0016Entry, "[in]") | 
|---|
| 120 | IN_QUERY_BODY(16, true) | 
|---|
| 121 | FINISH_BENCHMARK(NotInList0016Entry) | 
|---|
| 122 |  | 
|---|
| 123 | DUCKDB_BENCHMARK(NotInList0032Entry, "[in]") | 
|---|
| 124 | IN_QUERY_BODY(32, true) | 
|---|
| 125 | FINISH_BENCHMARK(NotInList0032Entry) | 
|---|
| 126 |  | 
|---|
| 127 | DUCKDB_BENCHMARK(NotInList0064Entry, "[in]") | 
|---|
| 128 | IN_QUERY_BODY(64, true) | 
|---|
| 129 | FINISH_BENCHMARK(NotInList0064Entry) | 
|---|
| 130 |  | 
|---|
| 131 | DUCKDB_BENCHMARK(NotInList0128Entry, "[in]") | 
|---|
| 132 | IN_QUERY_BODY(128, true) | 
|---|
| 133 | FINISH_BENCHMARK(NotInList0128Entry) | 
|---|
| 134 |  | 
|---|
| 135 | DUCKDB_BENCHMARK(NotInList0256Entry, "[in]") | 
|---|
| 136 | IN_QUERY_BODY(256, true) | 
|---|
| 137 | FINISH_BENCHMARK(NotInList0256Entry) | 
|---|
| 138 |  | 
|---|
| 139 | DUCKDB_BENCHMARK(NotInList0512Entry, "[in]") | 
|---|
| 140 | IN_QUERY_BODY(512, true) | 
|---|
| 141 | FINISH_BENCHMARK(NotInList0512Entry) | 
|---|
| 142 |  | 
|---|
| 143 | DUCKDB_BENCHMARK(NotInList1024Entry, "[in]") | 
|---|
| 144 | IN_QUERY_BODY(1024, true) | 
|---|
| 145 | FINISH_BENCHMARK(NotInList1024Entry) | 
|---|
| 146 |  | 
|---|
| 147 | DUCKDB_BENCHMARK(NotInList2048Entry, "[in]") | 
|---|
| 148 | IN_QUERY_BODY(2048, true) | 
|---|
| 149 | FINISH_BENCHMARK(NotInList2048Entry) | 
|---|
| 150 |  | 
|---|