/ Check-in [a7dca29f]
Login

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

Overview
Comment:In kvtest.c, use stat() instead of fseek()/ftell() to determine the size of a BLOB to be read directly from disk. This makes the pile-of-files database more competative against SQLite.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a7dca29f03e037fe71cc600db97f8058e3bd28a4
User & Date: drh 2016-12-29 17:25:06
Context
2016-12-29
19:48
Fix harmless compiler warnings in the command-line shell and in Lemon. check-in: afcdc4a6 user: drh tags: trunk
17:25
In kvtest.c, use stat() instead of fseek()/ftell() to determine the size of a BLOB to be read directly from disk. This makes the pile-of-files database more competative against SQLite. check-in: a7dca29f user: drh tags: trunk
16:58
Add the kvtest.c test program used to show that it is many times faster to read thumbnail and similar BLOBs out of an SQLite database than it is to read them as separate files from the filesystem. check-in: 8074d59c user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/kvtest.c.

   100    100   
   101    101   #ifndef _WIN32
   102    102   # include <unistd.h>
   103    103   #else
   104    104     /* Provide Windows equivalent for the needed parts of unistd.h */
   105    105   # include <io.h>
   106    106   # define R_OK 2
          107  +# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
   107    108   # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
   108    109   # define access _access
   109    110   #endif
   110    111   
   111    112   
   112    113   /*
   113    114   ** Show thqe help text and quit.
................................................................................
   149    150     memset(&x, 0, sizeof(x));
   150    151     rc = stat(zPath, &x);
   151    152     if( rc<0 ) return PATH_OTHER;
   152    153     if( S_ISDIR(x.st_mode) ) return PATH_DIR;
   153    154     if( (x.st_size%512)==0 ) return PATH_DB;
   154    155     return PATH_OTHER;
   155    156   }
          157  +
          158  +/*
          159  +** Return the size of a file in bytes.  Or return -1 if the
          160  +** named object is not a regular file or does not exist.
          161  +*/
          162  +static sqlite3_int64 fileSize(const char *zPath){
          163  +  struct stat x;
          164  +  int rc;
          165  +  memset(&x, 0, sizeof(x));
          166  +  rc = stat(zPath, &x);
          167  +  if( rc<0 ) return -1;
          168  +  if( !S_ISREG(x.st_mode) ) return -1;
          169  +  return x.st_size;
          170  +}
   156    171   
   157    172   /*
   158    173   ** A Pseudo-random number generator with a fixed seed.  Use this so
   159    174   ** that the same sequence of "random" numbers are generated on each
   160    175   ** run, for repeatability.
   161    176   */
   162    177   static unsigned int randInt(void){
................................................................................
   311    326   ** from the file before the buffer is returned. This byte is not included in
   312    327   ** the final value of (*pnByte), if applicable.
   313    328   **
   314    329   ** NULL is returned if any error is encountered. The final value of *pnByte
   315    330   ** is undefined in this case.
   316    331   */
   317    332   static unsigned char *readFile(const char *zName, int *pnByte){
   318         -  FILE *in = fopen(zName, "rb");
   319         -  long nIn;
   320         -  size_t nRead;
   321         -  unsigned char *pBuf;
          333  +  FILE *in;               /* FILE from which to read content of zName */
          334  +  sqlite3_int64 nIn;      /* Size of zName in bytes */
          335  +  size_t nRead;           /* Number of bytes actually read */
          336  +  unsigned char *pBuf;    /* Content read from disk */
          337  +
          338  +  nIn = fileSize(zName);
          339  +  if( nIn<0 ) return 0;
          340  +  in = fopen(zName, "rb");
   322    341     if( in==0 ) return 0;
   323         -  fseek(in, 0, SEEK_END);
   324         -  nIn = ftell(in);
   325         -  rewind(in);
   326         -  pBuf = sqlite3_malloc64( nIn+1 );
          342  +  pBuf = sqlite3_malloc64( nIn );
   327    343     if( pBuf==0 ) return 0;
   328    344     nRead = fread(pBuf, nIn, 1, in);
   329    345     fclose(in);
   330    346     if( nRead!=1 ){
   331    347       sqlite3_free(pBuf);
   332    348       return 0;
   333    349     }
   334         -  pBuf[nIn] = 0;
   335    350     if( pnByte ) *pnByte = nIn;
   336    351     return pBuf;
   337    352   }
   338    353   
   339    354   /*
   340    355   ** Return the current time in milliseconds since the beginning of
   341    356   ** the Julian epoch.