Index: test/wordcount.c ================================================================== --- test/wordcount.c +++ test/wordcount.c @@ -11,28 +11,10 @@ ** The INPUTFILE name can be omitted, in which case input it taken from ** standard input. ** ** Option: ** -** --without-rowid Use a WITHOUT ROWID table to store the words. -** --insert Use INSERT mode (the default) -** --replace Use REPLACE mode -** --select Use SELECT mode -** --update Use UPDATE mode -** --delete Use DELETE mode -** --query Use QUERY mode -** --nocase Add the NOCASE collating sequence to the words. -** --trace Enable sqlite3_trace() output. -** --summary Show summary information on the collected data. -** --stats Show sqlite3_status() results at the end. -** --pagesize NNN Use a page size of NNN -** --cachesize NNN Use a cache size of NNN -** --commit NNN Commit after every NNN operations -** --nosync Use PRAGMA synchronous=OFF -** --journal MMMM Use PRAGMA journal_mode=MMMM -** --timer Time the operation of this program -** --tag NAME Tag all output using NAME. Use only stdout. ** ** Modes: ** ** Insert mode means: ** (1) INSERT OR IGNORE INTO wordcount VALUES($new,1) @@ -79,11 +61,39 @@ #include #include #include #include #include "sqlite3.h" +#ifndef _WIN32 +# include +#else +# include +#endif #define ISALPHA(X) isalpha((unsigned char)(X)) + +const char zHelp[] = +"Usage: wordcount [OPTIONS] DATABASE [INPUT]\n" +" --all Repeat the test for all test modes\n" +" --cachesize NNN Use a cache size of NNN\n" +" --commit NNN Commit after every NNN operations\n" +" --delete Use DELETE mode\n" +" --insert Use INSERT mode (the default)\n" +" --journal MMMM Use PRAGMA journal_mode=MMMM\n" +" --nocase Add the NOCASE collating sequence to the words.\n" +" --nosync Use PRAGMA synchronous=OFF\n" +" --pagesize NNN Use a page size of NNN\n" +" --query Use QUERY mode\n" +" --replace Use REPLACE mode\n" +" --select Use SELECT mode\n" +" --stats Show sqlite3_status() results at the end.\n" +" --summary Show summary information on the collected data.\n" +" --tag NAME Tag all output using NAME. Use only stdout.\n" +" --timer Time the operation of this program\n" +" --trace Enable sqlite3_trace() output.\n" +" --update Use UPDATE mode\n" +" --without-rowid Use a WITHOUT ROWID table to store the words.\n" +; /* Output tag */ char *zTag = "--"; /* Return the current wall-clock time */ @@ -107,10 +117,16 @@ va_start(ap, zMsg); vfprintf(stderr, zMsg, ap); va_end(ap); exit(1); } + +/* Print a usage message and quit */ +static void usage(void){ + printf("%s",zHelp); + exit(0); +} /* The sqlite3_trace() callback function */ static void traceCallback(void *NotUsed, const char *zSql){ printf("%s;\n", zSql); } @@ -187,24 +203,61 @@ finalHash(a, zResult); sqlite3_result_text(context, zResult, -1, SQLITE_TRANSIENT); } } - /* Define operating modes */ #define MODE_INSERT 0 #define MODE_REPLACE 1 #define MODE_SELECT 2 #define MODE_UPDATE 3 #define MODE_DELETE 4 #define MODE_QUERY 5 +#define MODE_COUNT 6 +#define MODE_ALL (-1) + +/* Mode names */ +static const char *azMode[] = { + "--insert", + "--replace", + "--select", + "--update", + "--delete", + "--query" +}; + +/* +** Determine if another iteration of the test is required. Return true +** if so. Return zero if all iterations have finished. +*/ +static int allLoop( + int iMode, /* The selected test mode */ + int *piLoopCnt, /* Iteration loop counter */ + int *piMode2, /* The test mode to use on the next iteration */ + int *pUseWithoutRowid /* Whether or not to use --without-rowid */ +){ + int i; + if( iMode!=MODE_ALL ){ + if( *piLoopCnt ) return 0; + *piMode2 = iMode; + *piLoopCnt = 1; + return 1; + } + if( (*piLoopCnt)>=MODE_COUNT*2 ) return 0; + i = (*piLoopCnt)++; + *pUseWithoutRowid = i&1; + *piMode2 = i>>1; + return 1; +} int main(int argc, char **argv){ const char *zFileToRead = 0; /* Input file. NULL for stdin */ const char *zDbName = 0; /* Name of the database file to create */ int useWithoutRowid = 0; /* True for --without-rowid */ int iMode = MODE_INSERT; /* One of MODE_xxxxx */ + int iMode2; /* Mode to use for current --all iteration */ + int iLoopCnt = 0; /* Which iteration when running --all */ int useNocase = 0; /* True for --nocase */ int doTrace = 0; /* True for --trace */ int showStats = 0; /* True for --stats */ int showSummary = 0; /* True for --summary */ int showTimer = 0; /* True for --timer */ @@ -224,11 +277,12 @@ FILE *in; /* The open input file */ int rc; /* Return code from an SQLite interface */ int iCur, iHiwtr; /* Statistics values, current and "highwater" */ FILE *pTimer = stderr; /* Output channel for the timer */ sqlite3_int64 sumCnt = 0; /* Sum in QUERY mode */ - sqlite3_int64 startTime; + sqlite3_int64 startTime; /* Time of start */ + sqlite3_int64 totalTime = 0; /* Total time */ char zInput[2000]; /* A single line of input */ /* Process command-line arguments */ for(i=1; i0 && (nOp%commitInterval)==0 ){ - sqlite3_exec(db, "COMMIT; BEGIN IMMEDIATE", 0, 0, 0); - } - } - } - sqlite3_exec(db, "COMMIT", 0, 0, 0); - if( zFileToRead ) fclose(in); - sqlite3_finalize(pInsert); - sqlite3_finalize(pUpdate); - sqlite3_finalize(pSelect); - sqlite3_finalize(pDelete); - - if( iMode==MODE_QUERY ){ - printf("%s sum of cnt: %lld\n", zTag, sumCnt); - rc = sqlite3_prepare_v2(db,"SELECT sum(cnt*cnt) FROM wordcount", -1, - &pSelect, 0); - if( rc==SQLITE_OK && sqlite3_step(pSelect)==SQLITE_ROW ){ - printf("%s double-check: %lld\n", zTag, sqlite3_column_int64(pSelect, 0)); - } - sqlite3_finalize(pSelect); - } - - - if( showTimer ){ - sqlite3_int64 elapseTime = realTime() - startTime; - fprintf(pTimer, "%3d.%03d wordcount", (int)(elapseTime/1000), - (int)(elapseTime%1000)); - for(i=1; i0 && (nOp%commitInterval)==0 ){ + sqlite3_exec(db, "COMMIT; BEGIN IMMEDIATE", 0, 0, 0); + } + } + } + sqlite3_exec(db, "COMMIT", 0, 0, 0); + sqlite3_finalize(pInsert); pInsert = 0; + sqlite3_finalize(pUpdate); pUpdate = 0; + sqlite3_finalize(pSelect); pSelect = 0; + sqlite3_finalize(pDelete); pDelete = 0; + + if( iMode2==MODE_QUERY && iMode!=MODE_ALL ){ + printf("%s sum of cnt: %lld\n", zTag, sumCnt); + rc = sqlite3_prepare_v2(db,"SELECT sum(cnt*cnt) FROM wordcount", -1, + &pSelect, 0); + if( rc==SQLITE_OK && sqlite3_step(pSelect)==SQLITE_ROW ){ + printf("%s double-check: %lld\n", zTag,sqlite3_column_int64(pSelect,0)); + } + sqlite3_finalize(pSelect); + } + + + if( showTimer ){ + sqlite3_int64 elapseTime = realTime() - startTime; + totalTime += elapseTime; + fprintf(pTimer, "%3d.%03d wordcount", (int)(elapseTime/1000), + (int)(elapseTime%1000)); + if( iMode==MODE_ALL ){ + fprintf(pTimer, " %s%s\n", azMode[iMode2], + useWithoutRowid? " --without-rowid" : ""); + }else{ + for(i=1; i