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