-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathmain.c
More file actions
203 lines (180 loc) · 7.81 KB
/
main.c
File metadata and controls
203 lines (180 loc) · 7.81 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.
#include "bench.h"
// Comma-separated list of operations to run in the specified order
// Actual benchmarks:
//
// fillseq -- write N values in sequential key order in async mode
// fillseqsync -- write N/100 values in sequential key order in sync mode
// fillseqbatch -- batch write N values in sequential key order in async mode
// fillrandom -- write N values in random key order in async mode
// fillrandsync -- write N/100 values in random key order in sync mode
// fillrandbatch -- batch write N values in sequential key order in async mode
// overwrite -- overwrite N values in random key order in async mode
// fillrand100K -- write N/1000 100K values in random order in async mode
// fillseq100K -- write N/1000 100K values in sequential order in async mode
// readseq -- read N times sequentially
// readrandom -- read N times in random order
// readrand100K -- read N/1000 100K values in sequential order in async mode
char* FLAGS_benchmarks;
// Number of key/values to place in database
int FLAGS_num;
// Number of read operations to do. If negative, do FLAGS_num reads.
int FLAGS_reads;
// Size of each value
int FLAGS_value_size;
// Print histogram of operation timings
bool FLAGS_histogram;
// Print raw data
bool FLAGS_raw;
// Arrange to generate values that shrink to this fraction of
// their original size after compression
double FLAGS_compression_ratio;
// Page size. Default 1 KB.
int FLAGS_page_size;
// Number of pages.
// Default cache size = FLAGS_page_size * FLAGS_num_pages = 4 MB.
int FLAGS_num_pages;
// If true, do not destroy the existing database. If you set this
// flag and also specify a benchmark that wants a fresh database, that
// benchmark will fail.
bool FLAGS_use_existing_db;
// If true, we allow batch writes to occur
bool FLAGS_transaction;
// If true, we enable Write-Ahead Logging
bool FLAGS_WAL_enabled;
// Use the db with the following name.
char* FLAGS_db;
void init() {
// Comma-separated list of operations to run in the specified order
// Actual benchmarks:
//
// fillseq -- write N values in sequential key order in async mode
// fillseqsync -- write N/100 values in sequential key order in sync mode
// fillseqbatch -- batch write N values in sequential key order in async mode
// fillrandom -- write N values in random key order in async mode
// fillrandsync -- write N/100 values in random key order in sync mode
// fillrandbatch -- batch write N values in sequential key order in async mode
// overwrite -- overwrite N values in random key order in async mode
// fillrand100K -- write N/1000 100K values in random order in async mode
// fillseq100K -- write N/1000 100K values in sequential order in async mode
// readseq -- read N times sequentially
// readrandom -- read N times in random order
// readrand100K -- read N/1000 100K values in sequential order in async mode
FLAGS_benchmarks =
"fillseq,"
"fillseqsync,"
"fillseqbatch,"
"fillrandom,"
"fillrandsync,"
"fillrandbatch,"
"overwrite,"
"overwritebatch,"
"readrandom,"
"readseq,"
"fillrand100K,"
"fillseq100K,"
"readseq,"
"readrand100K,"
;
FLAGS_num = 1000000;
FLAGS_reads = -1;
FLAGS_value_size = 100;
FLAGS_histogram = false;
FLAGS_raw = false,
FLAGS_compression_ratio = 0.5;
FLAGS_page_size = 1024;
FLAGS_num_pages = 4096;
FLAGS_use_existing_db = false;
FLAGS_transaction = true;
FLAGS_WAL_enabled = true;
FLAGS_db = NULL;
}
void print_usage(const char* argv0) {
fprintf(stderr, "Usage: %s [OPTION]...\n", argv0);
fprintf(stderr, "SQLite3 benchmark tool\n");
fprintf(stderr, "[OPTION]\n");
fprintf(stderr, " --benchmarks=[BENCH]\t\tspecify benchmark\n");
fprintf(stderr, " --histogram={0,1}\t\trecord histogram\n");
fprintf(stderr, " --raw={0,1}\t\t\toutput raw data\n");
fprintf(stderr, " --compression_ratio=DOUBLE\tcompression ratio\n");
fprintf(stderr, " --use_existing_db={0,1}\tuse existing database\n");
fprintf(stderr, " --num=INT\t\t\tnumber of entries\n");
fprintf(stderr, " --reads=INT\t\t\tnumber of reads\n");
fprintf(stderr, " --value_size=INT\t\tvalue size\n");
fprintf(stderr, " --no_transaction\t\tdisable transaction\n");
fprintf(stderr, " --page_size=INT\t\tpage size\n");
fprintf(stderr, " --num_pages=INT\t\tnumber of pages\n");
fprintf(stderr, " --WAL_enabled={0,1}\t\tenable WAL\n");
fprintf(stderr, " --db=PATH\t\t\tpath to location databases are created\n");
fprintf(stderr, " --help\t\t\tshow this help\n");
fprintf(stderr, "\n");
fprintf(stderr, "[BENCH]\n");
fprintf(stderr, " fillseq\twrite N values in sequential key order in async mode\n");
fprintf(stderr, " fillseqsync\twrite N/100 values in sequential key order in sync mode\n");
fprintf(stderr, " fillseqbatch\tbatch write N values in sequential key order in async mode\n");
fprintf(stderr, " fillrandom\twrite N values in random key order in async mode\n");
fprintf(stderr, " fillrandsync\twrite N/100 values in random key order in sync mode\n");
fprintf(stderr, " fillrandbatch\tbatch write N values in random key order in async mode\n");
fprintf(stderr, " overwrite\toverwrite N values in random key order in async mode\n");
fprintf(stderr, " fillrand100K\twrite N/1000 100K values in random order in async mode\n");
fprintf(stderr, " fillseq100K\twirte N/1000 100K values in sequential order in async mode\n");
fprintf(stderr, " readseq\tread N times sequentially\n");
fprintf(stderr, " readrandom\tread N times in random order\n");
fprintf(stderr, " readrand100K\tread N/1000 100K values in sequential order in async mode\n");
}
int main(int argc, char** argv) {
init();
char* default_db_path = malloc(sizeof(char) * 1024);
strcpy(default_db_path, "./");
for (int i = 1; i < argc; i++) {
double d;
int n;
char junk;
if (starts_with(argv[i], "--benchmarks=")) {
FLAGS_benchmarks = argv[i] + strlen("--benchmarks=");
} else if (sscanf(argv[i], "--histogram=%d%c", &n, &junk) == 1 &&
(n == 0 || n == 1)) {
FLAGS_histogram = n;
} else if (sscanf(argv[i], "--raw=%d%c", &n, &junk) == 1 &&
(n == 0 || n == 1)) {
FLAGS_raw = n;
} else if (sscanf(argv[i], "--compression_ratio=%lf%c", &d, &junk) == 1) {
FLAGS_compression_ratio = d;
} else if (sscanf(argv[i], "--use_existing_db=%d%c", &n, &junk) == 1 &&
(n == 0 || n == 1)) {
FLAGS_use_existing_db = n;
} else if (sscanf(argv[i], "--num=%d%c", &n, &junk) == 1) {
FLAGS_num = n;
} else if (sscanf(argv[i], "--reads=%d%c", &n, &junk) == 1) {
FLAGS_reads = n;
} else if (sscanf(argv[i], "--value_size=%d%c", &n, &junk) == 1) {
FLAGS_value_size = n;
} else if (!strcmp(argv[i], "--no_transaction")) {
FLAGS_transaction = false;
} else if (sscanf(argv[i], "--page_size=%d%c", &n, &junk) == 1) {
FLAGS_page_size = n;
} else if (sscanf(argv[i], "--num_pages=%d%c", &n, &junk) == 1) {
FLAGS_num_pages = n;
} else if (sscanf(argv[i], "--WAL_enabled=%d%c", &n, &junk) == 1 &&
(n == 0 || n == 1)) {
FLAGS_WAL_enabled = n;
} else if (strncmp(argv[i], "--db=", 5) == 0) {
FLAGS_db = argv[i] + 5;
} else if (!strcmp(argv[i], "--help")) {
print_usage(argv[0]);
exit(0);
} else {
fprintf(stderr, "Invalid flag '%s'\n", argv[i]);
exit(1);
}
}
/* Choose a location for the test database if none given with --db=<path> */
if (FLAGS_db == NULL)
FLAGS_db = default_db_path;
benchmark_init();
benchmark_run();
benchmark_fini();
return 0;
}