| 1 |
/* |
| 2 |
* See the file LICENSE for redistribution information. |
| 3 |
* |
| 4 |
* Copyright (c) 2005, 2013 Oracle and/or its affiliates. All rights reserved. |
| 5 |
* |
| 6 |
* $Id$ |
| 7 |
*/ |
| 8 |
#include "bench.h" |
| 9 |
|
| 10 |
static int b_curalloc_usage(void); |
| 11 |
|
| 12 |
int |
| 13 |
b_curalloc(int argc, char *argv[]) |
| 14 |
{ |
| 15 |
extern char *optarg; |
| 16 |
extern int optind, __db_getopt_reset; |
| 17 |
DB *dbp; |
| 18 |
DBC *curp; |
| 19 |
int ch, i, count; |
| 20 |
|
| 21 |
count = 100000; |
| 22 |
__db_getopt_reset = 1; |
| 23 |
while ((ch = getopt(argc, argv, "c:")) != EOF) |
| 24 |
switch (ch) { |
| 25 |
case 'c': |
| 26 |
count = atoi(optarg); |
| 27 |
break; |
| 28 |
case '?': |
| 29 |
default: |
| 30 |
return (b_curalloc_usage()); |
| 31 |
} |
| 32 |
argc -= optind; |
| 33 |
argv += optind; |
| 34 |
if (argc != 0) |
| 35 |
return (b_curalloc_usage()); |
| 36 |
|
| 37 |
/* Create the database. */ |
| 38 |
DB_BENCH_ASSERT(db_create(&dbp, NULL, 0) == 0); |
| 39 |
dbp->set_errfile(dbp, stderr); |
| 40 |
|
| 41 |
#if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1) |
| 42 |
DB_BENCH_ASSERT(dbp->open( |
| 43 |
dbp, NULL, TESTFILE, NULL, DB_BTREE, DB_CREATE, 0666) == 0); |
| 44 |
#else |
| 45 |
DB_BENCH_ASSERT( |
| 46 |
dbp->open(dbp, TESTFILE, NULL, DB_BTREE, DB_CREATE, 0666) == 0); |
| 47 |
#endif |
| 48 |
|
| 49 |
/* Allocate a cursor count times. */ |
| 50 |
TIMER_START; |
| 51 |
for (i = 0; i < count; ++i) { |
| 52 |
DB_BENCH_ASSERT(dbp->cursor(dbp, NULL, &curp, 0) == 0); |
| 53 |
DB_BENCH_ASSERT(curp->c_close(curp) == 0); |
| 54 |
} |
| 55 |
TIMER_STOP; |
| 56 |
|
| 57 |
printf("# %d cursor allocations\n", count); |
| 58 |
TIMER_DISPLAY(count); |
| 59 |
|
| 60 |
DB_BENCH_ASSERT(dbp->close(dbp, 0) == 0); |
| 61 |
|
| 62 |
return (0); |
| 63 |
} |
| 64 |
|
| 65 |
static int |
| 66 |
b_curalloc_usage() |
| 67 |
{ |
| 68 |
(void)fprintf(stderr, "usage: b_curalloc [-c count]\n"); |
| 69 |
return (EXIT_FAILURE); |
| 70 |
} |