1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Improved option handling in speedtest8.c. Added -quiet and -priority options. Added reporting of total user and system time. (CVS 5070)

FossilOrigin-Name: aa59974ec15508d69c5b65ab89ec7bc32690018c
This commit is contained in:
shane
2008-04-30 15:55:33 +00:00
parent f96d8aebf3
commit 0068b225ff
3 changed files with 331 additions and 282 deletions

View File

@ -1,5 +1,5 @@
C Fix\stest\sfor\sbuffer\soverrun\sin\sunixGettempname().\sFix\sfor\s#3091.\s(CVS\s5069) C Improved\soption\shandling\sin\sspeedtest8.c.\s\sAdded\s-quiet\sand\s-priority\soptions.\s\sAdded\sreporting\sof\stotal\suser\sand\ssystem\stime.\s(CVS\s5070)
D 2008-04-30T08:56:10 D 2008-04-30T15:55:34
F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
F Makefile.in 25b3282a4ac39388632c2fb0e044ff494d490952 F Makefile.in 25b3282a4ac39388632c2fb0e044ff494d490952
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -573,7 +573,7 @@ F tool/spaceanal.tcl b87db46ae29e3116411b1686e136b9b994d7de39
F tool/speedtest.tcl 06c76698485ccf597b9e7dbb1ac70706eb873355 F tool/speedtest.tcl 06c76698485ccf597b9e7dbb1ac70706eb873355
F tool/speedtest16.c 6f5bc019dcf8b6537f379bbac0408a9e1a86f0b6 F tool/speedtest16.c 6f5bc019dcf8b6537f379bbac0408a9e1a86f0b6
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c fd53bf13c7bbea4671faa2222cbb3286c14200f8 F tool/speedtest8.c a7cd2b2dbb8f97b0c51c0e01f49116a9162071be
F tool/speedtest8inst1.c 025879132979a5fdec11218472cba6cf8f6ec854 F tool/speedtest8inst1.c 025879132979a5fdec11218472cba6cf8f6ec854
F www/34to35.tcl 942e479aa7740b55d714dce0f0b2cb6ca91c3f20 F www/34to35.tcl 942e479aa7740b55d714dce0f0b2cb6ca91c3f20
F www/arch.fig d5f9752a4dbf242e9cfffffd3f5762b6c63b3bcf F www/arch.fig d5f9752a4dbf242e9cfffffd3f5762b6c63b3bcf
@ -633,7 +633,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5 F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
P f854ae576ee0b223b86a1169178fc4399e8d08ce P fc0ca647bd1c7c953bb0f3eb7d3471572fd18c34
R dc0d12af7248df7518eb5354b7eeb383 R 8bd12bf8a3eaadb4e117c1f015393938
U danielk1977 U shane
Z 6533bd0cfc41b7cb37a38e5960f73499 Z 09702a98c8183287a6fdc49d86797b33

View File

@ -1 +1 @@
fc0ca647bd1c7c953bb0f3eb7d3471572fd18c34 aa59974ec15508d69c5b65ab89ec7bc32690018c

View File

@ -1,274 +1,323 @@
/* /*
** Performance test for SQLite. ** Performance test for SQLite.
** **
** This program reads ASCII text from a file named on the command-line ** This program reads ASCII text from a file named on the command-line
** and submits that text to SQLite for evaluation. A new database ** and submits that text to SQLite for evaluation. A new database
** is created at the beginning of the program. All statements are ** is created at the beginning of the program. All statements are
** timed using the high-resolution timer built into Intel-class processors. ** timed using the high-resolution timer built into Intel-class processors.
** **
** To compile this program, first compile the SQLite library separately ** To compile this program, first compile the SQLite library separately
** will full optimizations. For example: ** will full optimizations. For example:
** **
** gcc -c -O6 -DSQLITE_THREADSAFE=0 sqlite3.c ** gcc -c -O6 -DSQLITE_THREADSAFE=0 sqlite3.c
** **
** Then link against this program. But to do optimize this program ** Then link against this program. But to do optimize this program
** because that defeats the hi-res timer. ** because that defeats the hi-res timer.
** **
** gcc speedtest8.c sqlite3.o -ldl ** gcc speedtest8.c sqlite3.o -ldl
** **
** Then run this program with a single argument which is the name of ** Then run this program with a single argument which is the name of
** a file containing SQL script that you want to test: ** a file containing SQL script that you want to test:
** **
** ./a.out test.db test.sql ** ./a.out test.db test.sql
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include <unistd.h> #include <unistd.h>
#include "sqlite3.h" #include <sys/times.h>
#include <time.h>
#include <sched.h>
/*
** The following routine only works on pentium-class processors. #include "sqlite3.h"
** It uses the RDTSC opcode to read the cycle count value out of the
** processor and returns that value. This can be used for high-res /*
** profiling. ** The following routine only works on pentium-class processors.
*/ ** It uses the RDTSC opcode to read the cycle count value out of the
__inline__ unsigned long long int hwtime(void){ ** processor and returns that value. This can be used for high-res
unsigned int lo, hi; ** profiling.
/* We cannot use "=A", since this would use %rax on x86_64 */ */
__asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); __inline__ unsigned long long int hwtime(void){
return (unsigned long long int)hi << 32 | lo; unsigned int lo, hi;
} /* We cannot use "=A", since this would use %rax on x86_64 */
__asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
/* return (unsigned long long int)hi << 32 | lo;
** Timers }
*/
static unsigned long long int prepTime = 0; /*
static unsigned long long int runTime = 0; ** Timers
static unsigned long long int finalizeTime = 0; */
static unsigned long long int prepTime = 0;
/* static unsigned long long int runTime = 0;
** Prepare and run a single statement of SQL. static unsigned long long int finalizeTime = 0;
*/
static void prepareAndRun(sqlite3 *db, const char *zSql){ /*
sqlite3_stmt *pStmt; ** Prepare and run a single statement of SQL.
const char *stmtTail; */
unsigned long long int iStart, iElapse; static void prepareAndRun(sqlite3 *db, const char *zSql, int bQuiet){
int rc; sqlite3_stmt *pStmt;
const char *stmtTail;
printf("****************************************************************\n"); unsigned long long int iStart, iElapse;
printf("SQL statement: [%s]\n", zSql); int rc;
iStart = hwtime();
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &stmtTail); if (!bQuiet) printf("****************************************************************\n");
iElapse = hwtime() - iStart; if (!bQuiet) printf("SQL statement: [%s]\n", zSql);
prepTime += iElapse; iStart = hwtime();
printf("sqlite3_prepare_v2() returns %d in %llu cycles\n", rc, iElapse); rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &stmtTail);
if( rc==SQLITE_OK ){ iElapse = hwtime() - iStart;
int nRow = 0; prepTime += iElapse;
iStart = hwtime(); if (!bQuiet) printf("sqlite3_prepare_v2() returns %d in %llu cycles\n", rc, iElapse);
while( (rc=sqlite3_step(pStmt))==SQLITE_ROW ){ nRow++; } if( rc==SQLITE_OK ){
iElapse = hwtime() - iStart; int nRow = 0;
runTime += iElapse; iStart = hwtime();
printf("sqlite3_step() returns %d after %d rows in %llu cycles\n", while( (rc=sqlite3_step(pStmt))==SQLITE_ROW ){ nRow++; }
rc, nRow, iElapse); iElapse = hwtime() - iStart;
iStart = hwtime(); runTime += iElapse;
rc = sqlite3_finalize(pStmt); if (!bQuiet) printf("sqlite3_step() returns %d after %d rows in %llu cycles\n",
iElapse = hwtime() - iStart; rc, nRow, iElapse);
finalizeTime += iElapse; iStart = hwtime();
printf("sqlite3_finalize() returns %d in %llu cycles\n", rc, iElapse); rc = sqlite3_finalize(pStmt);
} iElapse = hwtime() - iStart;
} finalizeTime += iElapse;
if (!bQuiet) printf("sqlite3_finalize() returns %d in %llu cycles\n", rc, iElapse);
/*************************************************************************** }
** The "overwrite" VFS is an overlay over the default VFS. It modifies }
** the xTruncate operation on journal files so that xTruncate merely
** writes zeros into the first 50 bytes of the file rather than truely /***************************************************************************
** truncating the file. ** The "overwrite" VFS is an overlay over the default VFS. It modifies
** ** the xTruncate operation on journal files so that xTruncate merely
** The following variables are initialized to be the virtual function ** writes zeros into the first 50 bytes of the file rather than truely
** tables for the overwrite VFS. ** truncating the file.
*/ **
static sqlite3_vfs overwrite_vfs; ** The following variables are initialized to be the virtual function
static sqlite3_io_methods overwrite_methods; ** tables for the overwrite VFS.
*/
/* static sqlite3_vfs overwrite_vfs;
** The truncate method for journal files in the overwrite VFS. static sqlite3_io_methods overwrite_methods;
*/
static int overwriteTruncate(sqlite3_file *pFile, sqlite_int64 size){ /*
int rc; ** The truncate method for journal files in the overwrite VFS.
static const char buf[50]; */
if( size ){ static int overwriteTruncate(sqlite3_file *pFile, sqlite_int64 size){
return SQLITE_IOERR; int rc;
} static const char buf[50];
rc = pFile->pMethods->xWrite(pFile, buf, sizeof(buf), 0); if( size ){
if( rc==SQLITE_OK ){ return SQLITE_IOERR;
rc = pFile->pMethods->xSync(pFile, SQLITE_SYNC_NORMAL); }
} rc = pFile->pMethods->xWrite(pFile, buf, sizeof(buf), 0);
return rc; if( rc==SQLITE_OK ){
} rc = pFile->pMethods->xSync(pFile, SQLITE_SYNC_NORMAL);
}
/* return rc;
** The delete method for journal files in the overwrite VFS. }
*/
static int overwriteDelete(sqlite3_file *pFile){ /*
return overwriteTruncate(pFile, 0); ** The delete method for journal files in the overwrite VFS.
} */
static int overwriteDelete(sqlite3_file *pFile){
/* return overwriteTruncate(pFile, 0);
** The open method for overwrite VFS. If the file being opened is }
** a journal file then substitute the alternative xTruncate method.
*/ /*
static int overwriteOpen( ** The open method for overwrite VFS. If the file being opened is
sqlite3_vfs *pVfs, ** a journal file then substitute the alternative xTruncate method.
const char *zName, */
sqlite3_file *pFile, static int overwriteOpen(
int flags, sqlite3_vfs *pVfs,
int *pOutFlags const char *zName,
){ sqlite3_file *pFile,
int rc; int flags,
sqlite3_vfs *pRealVfs; int *pOutFlags
int isJournal; ){
int rc;
isJournal = (flags & (SQLITE_OPEN_MAIN_JOURNAL|SQLITE_OPEN_TEMP_JOURNAL))!=0; sqlite3_vfs *pRealVfs;
pRealVfs = (sqlite3_vfs*)pVfs->pAppData; int isJournal;
rc = pRealVfs->xOpen(pRealVfs, zName, pFile, flags, pOutFlags);
if( rc==SQLITE_OK && isJournal ){ isJournal = (flags & (SQLITE_OPEN_MAIN_JOURNAL|SQLITE_OPEN_TEMP_JOURNAL))!=0;
if( overwrite_methods.xTruncate==0 ){ pRealVfs = (sqlite3_vfs*)pVfs->pAppData;
sqlite3_io_methods temp; rc = pRealVfs->xOpen(pRealVfs, zName, pFile, flags, pOutFlags);
memcpy(&temp, pFile->pMethods, sizeof(temp)); if( rc==SQLITE_OK && isJournal ){
temp.xTruncate = overwriteTruncate; if( overwrite_methods.xTruncate==0 ){
memcpy(&overwrite_methods, &temp, sizeof(temp)); sqlite3_io_methods temp;
} memcpy(&temp, pFile->pMethods, sizeof(temp));
pFile->pMethods = &overwrite_methods; temp.xTruncate = overwriteTruncate;
} memcpy(&overwrite_methods, &temp, sizeof(temp));
return rc; }
} pFile->pMethods = &overwrite_methods;
}
/* return rc;
** Overlay the overwrite VFS over top of the current default VFS }
** and make the overlay VFS the new default.
** /*
** This routine can only be evaluated once. On second and subsequent ** Overlay the overwrite VFS over top of the current default VFS
** executions it becomes a no-op. ** and make the overlay VFS the new default.
*/ **
static void registerOverwriteVfs(void){ ** This routine can only be evaluated once. On second and subsequent
sqlite3_vfs *pBase; ** executions it becomes a no-op.
if( overwrite_vfs.iVersion ) return; */
pBase = sqlite3_vfs_find(0); static void registerOverwriteVfs(void){
memcpy(&overwrite_vfs, pBase, sizeof(overwrite_vfs)); sqlite3_vfs *pBase;
overwrite_vfs.pAppData = pBase; if( overwrite_vfs.iVersion ) return;
overwrite_vfs.xOpen = overwriteOpen; pBase = sqlite3_vfs_find(0);
overwrite_vfs.zName = "overwriteVfs"; memcpy(&overwrite_vfs, pBase, sizeof(overwrite_vfs));
sqlite3_vfs_register(&overwrite_vfs, 1); overwrite_vfs.pAppData = pBase;
} overwrite_vfs.xOpen = overwriteOpen;
overwrite_vfs.zName = "overwriteVfs";
int main(int argc, char **argv){ sqlite3_vfs_register(&overwrite_vfs, 1);
sqlite3 *db; }
int rc;
int nSql; int main(int argc, char **argv){
char *zSql; sqlite3 *db;
int i, j; int rc;
FILE *in; int nSql;
unsigned long long int iStart, iElapse; char *zSql;
unsigned long long int iSetup = 0; int i, j;
int nStmt = 0; FILE *in;
int nByte = 0; unsigned long long int iStart, iElapse;
const char *zArgv0 = argv[0]; unsigned long long int iSetup = 0;
int nStmt = 0;
#ifdef HAVE_OSINST int nByte = 0;
extern sqlite3_vfs *sqlite3_instvfs_binarylog(char *, char *, char *); const char *zArgv0 = argv[0];
extern void sqlite3_instvfs_destroy(sqlite3_vfs *); int bQuiet = 0;
sqlite3_vfs *pVfs = 0; struct tms tmsStart, tmsEnd;
#endif clock_t clkStart, clkEnd;
if( argc>=4 && strcmp(argv[1], "-overwrite")==0 ){ #ifdef HAVE_OSINST
registerOverwriteVfs(); extern sqlite3_vfs *sqlite3_instvfs_binarylog(char *, char *, char *);
argv++; extern void sqlite3_instvfs_destroy(sqlite3_vfs *);
argc--; sqlite3_vfs *pVfs = 0;
} #endif
#ifdef HAVE_OSINST while (argc>3)
if( argc>=5 && strcmp(argv[1], "-log")==0 ){ {
pVfs = sqlite3_instvfs_binarylog("oslog", 0, argv[2]); if( argc>3 && strcmp(argv[1], "-overwrite")==0 ){
sqlite3_vfs_register(pVfs, 1); registerOverwriteVfs();
argv += 2; argv++;
argc -= 2; argc--;
} continue;
#endif }
if( argc>=4 && strcmp(argv[1], "-overwrite")==0 ){ #ifdef HAVE_OSINST
registerOverwriteVfs(); if( argc>4 && (strcmp(argv[1], "-log")==0) ){
argv++; pVfs = sqlite3_instvfs_binarylog("oslog", 0, argv[2]);
argc--; sqlite3_vfs_register(pVfs, 1);
} argv += 2;
argc -= 2;
if( argc!=3 ){ continue;
fprintf(stderr, "Usage: %s [options] FILENAME SQL-SCRIPT\n" }
"Runs SQL-SCRIPT against a UTF8 database\n", #endif
zArgv0);
exit(1); /*
} ** Increasing the priority slightly above normal can help with repeatability
** of testing. Note that with Cygwin, -5 equates to "High", +5 equates to "Low",
in = fopen(argv[2], "r"); ** and anything in between equates to "Normal".
fseek(in, 0L, SEEK_END); */
nSql = ftell(in); if( argc>4 && (strcmp(argv[1], "-priority")==0) ){
zSql = malloc( nSql+1 ); struct sched_param myParam;
fseek(in, 0L, SEEK_SET); sched_getparam(0, &myParam);
nSql = fread(zSql, 1, nSql, in); printf ("Current process priority is %d.\n", (int)myParam.sched_priority);
zSql[nSql] = 0; myParam.sched_priority = atoi(argv[2]);
printf ("Setting process priority to %d.\n", (int)myParam.sched_priority);
printf("SQLite version: %d\n", sqlite3_libversion_number()); if (sched_setparam (0, &myParam) != 0){
unlink(argv[1]); printf ("error setting priority\n");
iStart = hwtime(); exit(2);
rc = sqlite3_open(argv[1], &db); }
iElapse = hwtime() - iStart; argv += 2;
iSetup = iElapse; argc -= 2;
printf("sqlite3_open() returns %d in %llu cycles\n", rc, iElapse); continue;
for(i=j=0; j<nSql; j++){ }
if( zSql[j]==';' ){
int isComplete; if( argc>3 && strcmp(argv[1], "-quiet")==0 ){
char c = zSql[j+1]; bQuiet = -1;
zSql[j+1] = 0; argv++;
isComplete = sqlite3_complete(&zSql[i]); argc--;
zSql[j+1] = c; continue;
if( isComplete ){ }
zSql[j] = 0;
while( i<j && isspace(zSql[i]) ){ i++; } break;
if( i<j ){ }
int n = j - i;
if( n>=6 && memcmp(&zSql[i], ".crash",6)==0 ) exit(1); if( argc!=3 ){
nStmt++; fprintf(stderr, "Usage: %s [options] FILENAME SQL-SCRIPT\n"
nByte += n; "Runs SQL-SCRIPT against a UTF8 database\n"
prepareAndRun(db, &zSql[i]); "\toptions:\n"
} "\t-overwrite\n"
zSql[j] = ';'; #ifdef HAVE_OSINST
i = j+1; "\t-log <log>\n"
} #endif
} "\t-priority <value> : set priority of task\n"
} "\t-quiet : only display summary results\n",
iStart = hwtime(); zArgv0);
sqlite3_close(db); exit(1);
iElapse = hwtime() - iStart; }
iSetup += iElapse;
printf("sqlite3_close() returns in %llu cycles\n", iElapse); in = fopen(argv[2], "r");
printf("\n"); fseek(in, 0L, SEEK_END);
printf("Statements run: %15d\n", nStmt); nSql = ftell(in);
printf("Bytes of SQL text: %15d\n", nByte); zSql = malloc( nSql+1 );
printf("Total prepare time: %15llu cycles\n", prepTime); fseek(in, 0L, SEEK_SET);
printf("Total run time: %15llu cycles\n", runTime); nSql = fread(zSql, 1, nSql, in);
printf("Total finalize time: %15llu cycles\n", finalizeTime); zSql[nSql] = 0;
printf("Open/Close time: %15llu cycles\n", iSetup);
printf("Total Time: %15llu cycles\n", printf("SQLite version: %d\n", sqlite3_libversion_number());
prepTime + runTime + finalizeTime + iSetup); unlink(argv[1]);
clkStart = times(&tmsStart);
#ifdef HAVE_OSINST iStart = hwtime();
if( pVfs ){ rc = sqlite3_open(argv[1], &db);
sqlite3_instvfs_destroy(pVfs); iElapse = hwtime() - iStart;
printf("vfs log written to %s\n", argv[0]); iSetup = iElapse;
} if (!bQuiet) printf("sqlite3_open() returns %d in %llu cycles\n", rc, iElapse);
#endif for(i=j=0; j<nSql; j++){
if( zSql[j]==';' ){
return 0; int isComplete;
} char c = zSql[j+1];
zSql[j+1] = 0;
isComplete = sqlite3_complete(&zSql[i]);
zSql[j+1] = c;
if( isComplete ){
zSql[j] = 0;
while( i<j && isspace(zSql[i]) ){ i++; }
if( i<j ){
int n = j - i;
if( n>=6 && memcmp(&zSql[i], ".crash",6)==0 ) exit(1);
nStmt++;
nByte += n;
prepareAndRun(db, &zSql[i], bQuiet);
}
zSql[j] = ';';
i = j+1;
}
}
}
iStart = hwtime();
sqlite3_close(db);
iElapse = hwtime() - iStart;
clkEnd = times(&tmsEnd);
iSetup += iElapse;
if (!bQuiet) printf("sqlite3_close() returns in %llu cycles\n", iElapse);
printf("\n");
printf("Statements run: %15d stmts\n", nStmt);
printf("Bytes of SQL text: %15d bytes\n", nByte);
printf("Total prepare time: %15llu cycles\n", prepTime);
printf("Total run time: %15llu cycles\n", runTime);
printf("Total finalize time: %15llu cycles\n", finalizeTime);
printf("Open/Close time: %15llu cycles\n", iSetup);
printf("Total time: %15llu cycles\n",
prepTime + runTime + finalizeTime + iSetup);
printf("\n");
printf("Total user CPU time: %15.3g secs\n", (tmsEnd.tms_utime - tmsStart.tms_utime)/(double)CLOCKS_PER_SEC );
printf("Total system CPU time: %15.3g secs\n", (tmsEnd.tms_stime - tmsStart.tms_stime)/(double)CLOCKS_PER_SEC );
printf("Total real time: %15.3g secs\n", (clkEnd -clkStart)/(double)CLOCKS_PER_SEC );
#ifdef HAVE_OSINST
if( pVfs ){
sqlite3_instvfs_destroy(pVfs);
printf("vfs log written to %s\n", argv[0]);
}
#endif
return 0;
}