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 MULTIPLICATION_ROW_COUNT 10000000
11
12DUCKDB_BENCHMARK(Multiplication, "[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, j INTEGER);");
20 Appender appender(state->conn, "integers"); // insert the elements into the database
21 for (size_t i = 0; i < MULTIPLICATION_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
29virtual string GetQuery() {
30 return "SELECT (i * j) + (i * j) + (i * j) + (i * j) FROM integers";
31}
32
33virtual string VerifyResult(QueryResult *result) {
34 if (!result->success) {
35 return result->error;
36 }
37 auto &materialized = (MaterializedQueryResult &)*result;
38 if (materialized.collection.count != MULTIPLICATION_ROW_COUNT) {
39 return "Incorrect amount of rows in result";
40 }
41 return string();
42}
43
44virtual string BenchmarkInfo() {
45 return StringUtil::Format("Runs the following query: \"" + GetQuery() +
46 "\""
47 " on %d rows",
48 MULTIPLICATION_ROW_COUNT);
49}
50FINISH_BENCHMARK(Multiplication)
51