Browse code

add --benchmark

John Hawthorn authored on 07/09/2014 00:59:26
Showing 1 changed files

  • fzy.c index 85b29fa..7ed00bb 100644
... ...
@@ -241,11 +241,13 @@ static struct option longopts[] = {
241 241
 	{ "lines", required_argument, NULL, 'l' },
242 242
 	{ "show-scores", no_argument, NULL, 's' },
243 243
 	{ "version", no_argument, NULL, 'v' },
244
+	{ "benchmark", no_argument, NULL, 'b' },
244 245
 	{ "help",    no_argument, NULL, 'h' },
245 246
 	{ NULL,      0,           NULL, 0 }
246 247
 };
247 248
 
248 249
 int main(int argc, char *argv[]){
250
+	int benchmark = 0;
249 251
 	char *initial_query = NULL;
250 252
 	char c;
251 253
 	while((c = getopt_long(argc, argv, "vhse:l:", longopts, NULL)) != -1){
... ...
@@ -259,6 +261,9 @@ int main(int argc, char *argv[]){
259 261
 			case 'e':
260 262
 				initial_query = optarg;
261 263
 				break;
264
+			case 'b':
265
+				benchmark = 1;
266
+				break;
262 267
 			case 'l':
263 268
 				{
264 269
 					int l;
... ...
@@ -285,7 +290,14 @@ int main(int argc, char *argv[]){
285 290
 	resize_choices(INITIAL_CAPACITY);
286 291
 	read_choices();
287 292
 
288
-	if(initial_query){
293
+	if(benchmark){
294
+		if(!initial_query){
295
+			fprintf(stderr, "Must specify -e/--show-matches with --benchmark\n");
296
+			exit(EXIT_FAILURE);
297
+		}
298
+		for(int i = 0; i < 100; i++)
299
+			run_search(initial_query);
300
+	}else if(initial_query){
289 301
 		run_search(initial_query);
290 302
 		for(size_t i = 0; i < choices_available; i++){
291 303
 			size_t choice_idx = choices_sorted[i];