/ Check-in [a89fdf87]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the --timer option to the wordcount test program.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a89fdf87553f01c150729c570796b5078a9b069d
User & Date: drh 2013-11-21 19:27:45
Context
2013-11-21
20:48
Fix the code generator to honor turning off constant expression factoring. check-in: 88262266 user: drh tags: trunk
19:27
Add the --timer option to the wordcount test program. check-in: a89fdf87 user: drh tags: trunk
19:05
Remove a test from sqlite3VdbeMemFromBtree() which was unnecessary, and after the recent OP_Column refactoring, unreachable. check-in: 23667f3b user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/wordcount.c.

    25     25   **     --summary            Show summary information on the collected data.
    26     26   **     --stats              Show sqlite3_status() results at the end.
    27     27   **     --pagesize NNN       Use a page size of NNN
    28     28   **     --cachesize NNN      Use a cache size of NNN
    29     29   **     --commit NNN         Commit after every NNN operations
    30     30   **     --nosync             Use PRAGMA synchronous=OFF
    31     31   **     --journal MMMM       Use PRAGMA journal_mode=MMMM
           32  +**     --timer              Time the operation of this program
    32     33   **
    33     34   ** Modes:
    34     35   **
    35     36   ** Insert mode means:
    36     37   **    (1) INSERT OR IGNORE INTO wordcount VALUES($new,1)
    37     38   **    (2) UPDATE wordcount SET cnt=cnt+1 WHERE word=$new -- if (1) is a noop
    38     39   **
................................................................................
    75     76   */
    76     77   #include <stdio.h>
    77     78   #include <string.h>
    78     79   #include <ctype.h>
    79     80   #include <stdlib.h>
    80     81   #include <stdarg.h>
    81     82   #include "sqlite3.h"
           83  +
           84  +/* Return the current wall-clock time */
           85  +static sqlite3_int64 realTime(void){
           86  +  static sqlite3_vfs *clockVfs = 0;
           87  +  sqlite3_int64 t;
           88  +  if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(0);
           89  +  if( clockVfs->iVersion>=1 && clockVfs->xCurrentTimeInt64!=0 ){
           90  +    clockVfs->xCurrentTimeInt64(clockVfs, &t);
           91  +  }else{
           92  +    double r;
           93  +    clockVfs->xCurrentTime(clockVfs, &r);
           94  +    t = (sqlite3_int64)(r*86400000.0);
           95  +  }
           96  +  return t;
           97  +}
    82     98   
    83     99   /* Print an error message and exit */
    84    100   static void fatal_error(const char *zMsg, ...){
    85    101     va_list ap;
    86    102     va_start(ap, zMsg);
    87    103     vfprintf(stderr, zMsg, ap);
    88    104     va_end(ap);
................................................................................
   182    198     const char *zDbName = 0;      /* Name of the database file to create */
   183    199     int useWithoutRowid = 0;      /* True for --without-rowid */
   184    200     int iMode = MODE_INSERT;      /* One of MODE_xxxxx */
   185    201     int useNocase = 0;            /* True for --nocase */
   186    202     int doTrace = 0;              /* True for --trace */
   187    203     int showStats = 0;            /* True for --stats */
   188    204     int showSummary = 0;          /* True for --summary */
          205  +  int showTimer = 0;            /* True for --timer */
   189    206     int cacheSize = 0;            /* Desired cache size.  0 means default */
   190    207     int pageSize = 0;             /* Desired page size.  0 means default */
   191    208     int commitInterval = 0;       /* How often to commit.  0 means never */
   192    209     int noSync = 0;               /* True for --nosync */
   193    210     const char *zJMode = 0;       /* Journal mode */
   194    211     int nOp = 0;                  /* Operation counter */
   195    212     int i, j;                     /* Loop counters */
................................................................................
   199    216     sqlite3_stmt *pUpdate = 0;    /* The UPDATE statement */
   200    217     sqlite3_stmt *pSelect = 0;    /* The SELECT statement */
   201    218     sqlite3_stmt *pDelete = 0;    /* The DELETE statement */
   202    219     FILE *in;                     /* The open input file */
   203    220     int rc;                       /* Return code from an SQLite interface */
   204    221     int iCur, iHiwtr;             /* Statistics values, current and "highwater" */
   205    222     sqlite3_int64 sumCnt = 0;     /* Sum in QUERY mode */
          223  +  sqlite3_int64 startTime;
   206    224     char zInput[2000];            /* A single line of input */
   207    225   
   208    226     /* Process command-line arguments */
   209    227     for(i=1; i<argc; i++){
   210    228       const char *z = argv[i];
   211    229       if( z[0]=='-' ){
   212    230         do{ z++; }while( z[0]=='-' );
................................................................................
   230    248           doTrace = 1;
   231    249         }else if( strcmp(z,"nosync")==0 ){
   232    250           noSync = 1;
   233    251         }else if( strcmp(z,"stats")==0 ){
   234    252           showStats = 1;
   235    253         }else if( strcmp(z,"summary")==0 ){
   236    254           showSummary = 1;
          255  +      }else if( strcmp(z,"timer")==0 ){
          256  +        showTimer = i;
   237    257         }else if( strcmp(z,"cachesize")==0 && i<argc-1 ){
   238    258           i++;
   239    259           cacheSize = atoi(argv[i]);
   240    260         }else if( strcmp(z,"pagesize")==0 && i<argc-1 ){
   241    261           i++;
   242    262           pageSize = atoi(argv[i]);
   243    263         }else if( strcmp(z,"commit")==0 && i<argc-1 ){
................................................................................
   255    275       }else{
   256    276         fatal_error("surplus argument: %s\n", argv[i]);
   257    277       }
   258    278     }
   259    279     if( zDbName==0 ){
   260    280       fatal_error("Usage: %s [--options] DATABASE [INPUTFILE]\n", argv[0]);
   261    281     }
          282  +  startTime = realTime();
   262    283   
   263    284     /* Open the database and the input file */
   264    285     if( sqlite3_open(zDbName, &db) ){
   265    286       fatal_error("Cannot open database file: %s\n", zDbName);
   266    287     }
   267    288     if( zFileToRead ){
   268    289       in = fopen(zFileToRead, "rb");
................................................................................
   445    466                               &pSelect, 0);
   446    467       if( rc==SQLITE_OK && sqlite3_step(pSelect)==SQLITE_ROW ){
   447    468         printf("double-check: %lld\n", sqlite3_column_int64(pSelect, 0));
   448    469       }
   449    470       sqlite3_finalize(pSelect);
   450    471     }
   451    472   
          473  +
          474  +  if( showTimer ){
          475  +    sqlite3_int64 elapseTime = realTime() - startTime;
          476  +    printf("/* %3d.%03d", (int)(elapseTime/1000), (int)(elapseTime%1000));
          477  +    for(i=0; i<argc; i++) if( i!=showTimer ) printf(" %s", argv[i]);
          478  +    printf(" */\n");
          479  +  }
          480  +
   452    481     if( showSummary ){
   453    482       sqlite3_create_function(db, "checksum", -1, SQLITE_UTF8, 0,
   454    483                               0, checksumStep, checksumFinalize);
   455    484       sqlite3_exec(db, 
   456    485         "SELECT 'count(*):  ', count(*) FROM wordcount;\n"
   457    486         "SELECT 'sum(cnt):  ', sum(cnt) FROM wordcount;\n"
   458    487         "SELECT 'max(cnt):  ', max(cnt) FROM wordcount;\n"