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