2 ** A program for performance testing.
4 ** The available command-line options are described below:
6 static const char zHelp
[] =
7 "Usage: %s [--options] DATABASE\n"
9 " --autovacuum Enable AUTOVACUUM mode\n"
10 " --cachesize N Set the cache size to N\n"
11 " --exclusive Enable locking_mode=EXCLUSIVE\n"
12 " --explain Like --sqlonly but with added EXPLAIN keywords\n"
13 " --heap SZ MIN Memory allocator uses SZ bytes & min allocation MIN\n"
14 " --incrvacuum Enable incremenatal vacuum mode\n"
15 " --journal M Set the journal_mode to M\n"
16 " --key KEY Set the encryption key to KEY\n"
17 " --lookaside N SZ Configure lookaside for N slots of SZ bytes each\n"
18 " --mmap SZ MMAP the first SZ bytes of the database file\n"
19 " --multithread Set multithreaded mode\n"
20 " --nomemstat Disable memory statistics\n"
21 " --nosync Set PRAGMA synchronous=OFF\n"
22 " --notnull Add NOT NULL constraints to table columns\n"
23 " --pagesize N Set the page size to N\n"
24 " --pcache N SZ Configure N pages of pagecache each of size SZ bytes\n"
25 " --primarykey Use PRIMARY KEY instead of UNIQUE where appropriate\n"
26 " --repeat N Repeat each SELECT N times (default: 1)\n"
27 " --reprepare Reprepare each statement upon every invocation\n"
28 " --serialized Set serialized threading mode\n"
29 " --singlethread Set single-threaded mode - disables all mutexing\n"
30 " --sqlonly No-op. Only show the SQL that would have been run.\n"
31 " --shrink-memory Invoke sqlite3_db_release_memory() frequently.\n"
32 " --size N Relative test size. Default=100\n"
33 " --stats Show statistics at the end\n"
34 " --temp N N from 0 to 9. 0: no temp table. 9: all temp tables\n"
35 " --testset T Run test-set T (main, cte, rtree, orm, debug)\n"
36 " --trace Turn on SQL tracing\n"
37 " --threads N Use up to N threads for sorting\n"
38 " --utf16be Set text encoding to UTF-16BE\n"
39 " --utf16le Set text encoding to UTF-16LE\n"
40 " --verify Run additional verification steps.\n"
41 " --without-rowid Use WITHOUT ROWID where appropriate\n"
57 #define ISSPACE(X) isspace((unsigned char)(X))
58 #define ISDIGIT(X) isdigit((unsigned char)(X))
60 #if SQLITE_VERSION_NUMBER<3005000
61 # define sqlite3_int64 sqlite_int64
64 /* All global state is held in this structure */
65 static struct Global
{
66 sqlite3
*db
; /* The open database connection */
67 sqlite3_stmt
*pStmt
; /* Current SQL statement */
68 sqlite3_int64 iStart
; /* Start-time for the current test */
69 sqlite3_int64 iTotal
; /* Total time */
70 int bWithoutRowid
; /* True for --without-rowid */
71 int bReprepare
; /* True to reprepare the SQL on each rerun */
72 int bSqlOnly
; /* True to print the SQL once only */
73 int bExplain
; /* Print SQL with EXPLAIN prefix */
74 int bVerify
; /* Try to verify that results are correct */
75 int bMemShrink
; /* Call sqlite3_db_release_memory() often */
76 int eTemp
; /* 0: no TEMP. 9: always TEMP. */
77 int szTest
; /* Scale factor for test iterations */
78 int nRepeat
; /* Repeat selects this many times */
79 const char *zWR
; /* Might be WITHOUT ROWID */
80 const char *zNN
; /* Might be NOT NULL */
81 const char *zPK
; /* Might be UNIQUE or PRIMARY KEY */
82 unsigned int x
, y
; /* Pseudo-random number generator state */
83 int nResult
; /* Size of the current result */
84 char zResult
[3000]; /* Text of the current result */
87 /* Return " TEMP" or "", as appropriate for creating a table.
89 static const char *isTemp(int N
){
90 return g
.eTemp
>=N
? " TEMP" : "";
94 /* Print an error message and exit */
95 static void fatal_error(const char *zMsg
, ...){
98 vfprintf(stderr
, zMsg
, ap
);
104 ** Return the value of a hexadecimal digit. Return -1 if the input
105 ** is not a hex digit.
107 static int hexDigitValue(char c
){
108 if( c
>='0' && c
<='9' ) return c
- '0';
109 if( c
>='a' && c
<='f' ) return c
- 'a' + 10;
110 if( c
>='A' && c
<='F' ) return c
- 'A' + 10;
114 /* Provide an alternative to sqlite3_stricmp() in older versions of
116 #if SQLITE_VERSION_NUMBER<3007011
117 # define sqlite3_stricmp strcmp
121 ** Interpret zArg as an integer value, possibly with suffixes.
123 static int integerValue(const char *zArg
){
125 static const struct { char *zSuffix
; int iMult
; } aMult
[] = {
127 { "MiB", 1024*1024 },
128 { "GiB", 1024*1024*1024 },
131 { "GB", 1000000000 },
141 }else if( zArg
[0]=='+' ){
144 if( zArg
[0]=='0' && zArg
[1]=='x' ){
147 while( (x
= hexDigitValue(zArg
[0]))>=0 ){
152 while( isdigit(zArg
[0]) ){
153 v
= v
*10 + zArg
[0] - '0';
157 for(i
=0; i
<sizeof(aMult
)/sizeof(aMult
[0]); i
++){
158 if( sqlite3_stricmp(aMult
[i
].zSuffix
, zArg
)==0 ){
163 if( v
>0x7fffffff ) fatal_error("parameter too large - max 2147483648");
164 return (int)(isNeg
? -v
: v
);
167 /* Return the current wall-clock time, in milliseconds */
168 sqlite3_int64
speedtest1_timestamp(void){
169 #if SQLITE_VERSION_NUMBER<3005000
172 static sqlite3_vfs
*clockVfs
= 0;
174 if( clockVfs
==0 ) clockVfs
= sqlite3_vfs_find(0);
175 #if SQLITE_VERSION_NUMBER>=3007000
176 if( clockVfs
->iVersion
>=2 && clockVfs
->xCurrentTimeInt64
!=0 ){
177 clockVfs
->xCurrentTimeInt64(clockVfs
, &t
);
182 clockVfs
->xCurrentTime(clockVfs
, &r
);
183 t
= (sqlite3_int64
)(r
*86400000.0);
189 /* Return a pseudo-random unsigned integer */
190 unsigned int speedtest1_random(void){
191 g
.x
= (g
.x
>>1) ^ ((1+~(g
.x
&1)) & 0xd0000001);
192 g
.y
= g
.y
*1103515245 + 12345;
196 /* Map the value in within the range of 1...limit into another
197 ** number in a way that is chatic and invertable.
199 unsigned swizzle(unsigned in
, unsigned limit
){
202 out
= (out
<<1) | (in
&1);
209 /* Round up a number so that it is a power of two minus one
211 unsigned roundup_allones(unsigned limit
){
213 while( m
<limit
) m
= (m
<<1)+1;
217 /* The speedtest1_numbername procedure below converts its argment (an integer)
218 ** into a string which is the English-language name for that number.
219 ** The returned string should be freed with sqlite3_free().
223 ** speedtest1_numbername(123) -> "one hundred twenty three"
225 int speedtest1_numbername(unsigned int n
, char *zOut
, int nOut
){
226 static const char *ones
[] = { "zero", "one", "two", "three", "four", "five",
227 "six", "seven", "eight", "nine", "ten", "eleven", "twelve",
228 "thirteen", "fourteen", "fifteen", "sixteen", "seventeen",
229 "eighteen", "nineteen" };
230 static const char *tens
[] = { "", "ten", "twenty", "thirty", "forty",
231 "fifty", "sixty", "seventy", "eighty", "ninety" };
235 i
+= speedtest1_numbername(n
/1000000000, zOut
+i
, nOut
-i
);
236 sqlite3_snprintf(nOut
-i
, zOut
+i
, " billion");
237 i
+= (int)strlen(zOut
+i
);
241 if( i
&& i
<nOut
-1 ) zOut
[i
++] = ' ';
242 i
+= speedtest1_numbername(n
/1000000, zOut
+i
, nOut
-i
);
243 sqlite3_snprintf(nOut
-i
, zOut
+i
, " million");
244 i
+= (int)strlen(zOut
+i
);
248 if( i
&& i
<nOut
-1 ) zOut
[i
++] = ' ';
249 i
+= speedtest1_numbername(n
/1000, zOut
+i
, nOut
-i
);
250 sqlite3_snprintf(nOut
-i
, zOut
+i
, " thousand");
251 i
+= (int)strlen(zOut
+i
);
255 if( i
&& i
<nOut
-1 ) zOut
[i
++] = ' ';
256 sqlite3_snprintf(nOut
-i
, zOut
+i
, "%s hundred", ones
[n
/100]);
257 i
+= (int)strlen(zOut
+i
);
261 if( i
&& i
<nOut
-1 ) zOut
[i
++] = ' ';
262 sqlite3_snprintf(nOut
-i
, zOut
+i
, "%s", tens
[n
/10]);
263 i
+= (int)strlen(zOut
+i
);
267 if( i
&& i
<nOut
-1 ) zOut
[i
++] = ' ';
268 sqlite3_snprintf(nOut
-i
, zOut
+i
, "%s", ones
[n
]);
269 i
+= (int)strlen(zOut
+i
);
272 sqlite3_snprintf(nOut
-i
, zOut
+i
, "zero");
273 i
+= (int)strlen(zOut
+i
);
279 /* Start a new test case */
281 static const char zDots
[] =
282 ".......................................................................";
283 void speedtest1_begin_test(int iTestNum
, const char *zTestName
, ...){
284 int n
= (int)strlen(zTestName
);
287 va_start(ap
, zTestName
);
288 zName
= sqlite3_vmprintf(zTestName
, ap
);
290 n
= (int)strlen(zName
);
292 zName
[NAMEWIDTH
] = 0;
296 printf("/* %4d - %s%.*s */\n", iTestNum
, zName
, NAMEWIDTH
-n
, zDots
);
298 printf("%4d - %s%.*s ", iTestNum
, zName
, NAMEWIDTH
-n
, zDots
);
303 g
.iStart
= speedtest1_timestamp();
308 /* Complete a test case */
309 void speedtest1_end_test(void){
310 sqlite3_int64 iElapseTime
= speedtest1_timestamp() - g
.iStart
;
312 g
.iTotal
+= iElapseTime
;
313 printf("%4d.%03ds\n", (int)(iElapseTime
/1000), (int)(iElapseTime
%1000));
316 sqlite3_finalize(g
.pStmt
);
321 /* Report end of testing */
322 void speedtest1_final(void){
324 printf(" TOTAL%.*s %4d.%03ds\n", NAMEWIDTH
-5, zDots
,
325 (int)(g
.iTotal
/1000), (int)(g
.iTotal
%1000));
329 /* Print an SQL statement to standard output */
330 static void printSql(const char *zSql
){
331 int n
= (int)strlen(zSql
);
332 while( n
>0 && (zSql
[n
-1]==';' || ISSPACE(zSql
[n
-1])) ){ n
--; }
333 if( g
.bExplain
) printf("EXPLAIN ");
334 printf("%.*s;\n", n
, zSql
);
336 #if SQLITE_VERSION_NUMBER>=3007017
337 && ( sqlite3_strglob("CREATE *", zSql
)==0
338 || sqlite3_strglob("DROP *", zSql
)==0
339 || sqlite3_strglob("ALTER *", zSql
)==0
343 printf("%.*s;\n", n
, zSql
);
347 /* Shrink memory used, if appropriate and if the SQLite version is capable
350 void speedtest1_shrink_memory(void){
351 #if SQLITE_VERSION_NUMBER>=3007010
352 if( g
.bMemShrink
) sqlite3_db_release_memory(g
.db
);
357 void speedtest1_exec(const char *zFormat
, ...){
360 va_start(ap
, zFormat
);
361 zSql
= sqlite3_vmprintf(zFormat
, ap
);
367 int rc
= sqlite3_exec(g
.db
, zSql
, 0, 0, &zErrMsg
);
368 if( zErrMsg
) fatal_error("SQL error: %s\n%s\n", zErrMsg
, zSql
);
369 if( rc
!=SQLITE_OK
) fatal_error("exec error: %s\n", sqlite3_errmsg(g
.db
));
372 speedtest1_shrink_memory();
375 /* Prepare an SQL statement */
376 void speedtest1_prepare(const char *zFormat
, ...){
379 va_start(ap
, zFormat
);
380 zSql
= sqlite3_vmprintf(zFormat
, ap
);
386 if( g
.pStmt
) sqlite3_finalize(g
.pStmt
);
387 rc
= sqlite3_prepare_v2(g
.db
, zSql
, -1, &g
.pStmt
, 0);
389 fatal_error("SQL error: %s\n", sqlite3_errmsg(g
.db
));
395 /* Run an SQL statement previously prepared */
396 void speedtest1_run(void){
398 if( g
.bSqlOnly
) return;
401 while( sqlite3_step(g
.pStmt
)==SQLITE_ROW
){
402 n
= sqlite3_column_count(g
.pStmt
);
404 const char *z
= (const char*)sqlite3_column_text(g
.pStmt
, i
);
405 if( z
==0 ) z
= "nil";
406 len
= (int)strlen(z
);
407 if( g
.nResult
+len
<sizeof(g
.zResult
)-2 ){
408 if( g
.nResult
>0 ) g
.zResult
[g
.nResult
++] = ' ';
409 memcpy(g
.zResult
+ g
.nResult
, z
, len
+1);
414 #if SQLITE_VERSION_NUMBER>=3006001
417 sqlite3_prepare_v2(g
.db
, sqlite3_sql(g
.pStmt
), -1, &pNew
, 0);
418 sqlite3_finalize(g
.pStmt
);
423 sqlite3_reset(g
.pStmt
);
425 speedtest1_shrink_memory();
428 #ifndef SQLITE_OMIT_DEPRECATED
429 /* The sqlite3_trace() callback function */
430 static void traceCallback(void *NotUsed
, const char *zSql
){
431 int n
= (int)strlen(zSql
);
432 while( n
>0 && (zSql
[n
-1]==';' || ISSPACE(zSql
[n
-1])) ) n
--;
433 fprintf(stderr
,"%.*s;\n", n
, zSql
);
435 #endif /* SQLITE_OMIT_DEPRECATED */
437 /* Substitute random() function that gives the same random
438 ** sequence on each run, for repeatability. */
439 static void randomFunc(
440 sqlite3_context
*context
,
442 sqlite3_value
**NotUsed2
444 sqlite3_result_int64(context
, (sqlite3_int64
)speedtest1_random());
447 /* Estimate the square root of an integer */
448 static int est_square_root(int x
){
452 for(n
=0; y0
>0 && n
<10; n
++){
461 #if SQLITE_VERSION_NUMBER<3005004
463 ** An implementation of group_concat(). Used only when testing older
464 ** versions of SQLite that lack the built-in group_concat().
471 static void groupAppend(struct groupConcat
*p
, const char *z
, int n
){
472 if( p
->nUsed
+n
>= p
->nAlloc
){
473 int n2
= (p
->nAlloc
+n
+1)*2;
474 char *z2
= sqlite3_realloc(p
->z
, n2
);
479 memcpy(p
->z
+p
->nUsed
, z
, n
);
482 static void groupStep(
483 sqlite3_context
*context
,
488 struct groupConcat
*p
;
491 assert( argc
==1 || argc
==2 );
492 if( sqlite3_value_type(argv
[0])==SQLITE_NULL
) return;
493 p
= (struct groupConcat
*)sqlite3_aggregate_context(context
, sizeof(*p
));
496 int firstTerm
= p
->nUsed
==0;
499 zSep
= (char*)sqlite3_value_text(argv
[1]);
500 nSep
= sqlite3_value_bytes(argv
[1]);
505 if( nSep
) groupAppend(p
, zSep
, nSep
);
507 zVal
= (char*)sqlite3_value_text(argv
[0]);
508 nVal
= sqlite3_value_bytes(argv
[0]);
509 if( zVal
) groupAppend(p
, zVal
, nVal
);
512 static void groupFinal(sqlite3_context
*context
){
513 struct groupConcat
*p
;
514 p
= sqlite3_aggregate_context(context
, 0);
517 sqlite3_result_text(context
, p
->z
, p
->nUsed
, sqlite3_free
);
523 ** The main and default testset
525 void testset_main(void){
526 int i
; /* Loop counter */
527 int n
; /* iteration count */
528 int sz
; /* Size of the tables */
529 int maxb
; /* Maximum swizzled value */
530 unsigned x1
= 0, x2
= 0; /* Parameters */
531 int len
= 0; /* Length of the zNum[] string */
532 char zNum
[2000]; /* A number name */
534 sz
= n
= g
.szTest
*500;
536 maxb
= roundup_allones(sz
);
537 speedtest1_begin_test(100, "%d INSERTs into table with no index", n
);
538 speedtest1_exec("BEGIN");
539 speedtest1_exec("CREATE%s TABLE t1(a INTEGER %s, b INTEGER %s, c TEXT %s);",
540 isTemp(9), g
.zNN
, g
.zNN
, g
.zNN
);
541 speedtest1_prepare("INSERT INTO t1 VALUES(?1,?2,?3); -- %d times", n
);
543 x1
= swizzle(i
,maxb
);
544 speedtest1_numbername(x1
, zNum
, sizeof(zNum
));
545 sqlite3_bind_int64(g
.pStmt
, 1, (sqlite3_int64
)x1
);
546 sqlite3_bind_int(g
.pStmt
, 2, i
);
547 sqlite3_bind_text(g
.pStmt
, 3, zNum
, -1, SQLITE_STATIC
);
550 speedtest1_exec("COMMIT");
551 speedtest1_end_test();
555 speedtest1_begin_test(110, "%d ordered INSERTS with one index/PK", n
);
556 speedtest1_exec("BEGIN");
558 "CREATE%s TABLE t2(a INTEGER %s %s, b INTEGER %s, c TEXT %s) %s",
559 isTemp(5), g
.zNN
, g
.zPK
, g
.zNN
, g
.zNN
, g
.zWR
);
560 speedtest1_prepare("INSERT INTO t2 VALUES(?1,?2,?3); -- %d times", n
);
562 x1
= swizzle(i
,maxb
);
563 speedtest1_numbername(x1
, zNum
, sizeof(zNum
));
564 sqlite3_bind_int(g
.pStmt
, 1, i
);
565 sqlite3_bind_int64(g
.pStmt
, 2, (sqlite3_int64
)x1
);
566 sqlite3_bind_text(g
.pStmt
, 3, zNum
, -1, SQLITE_STATIC
);
569 speedtest1_exec("COMMIT");
570 speedtest1_end_test();
574 speedtest1_begin_test(120, "%d unordered INSERTS with one index/PK", n
);
575 speedtest1_exec("BEGIN");
577 "CREATE%s TABLE t3(a INTEGER %s %s, b INTEGER %s, c TEXT %s) %s",
578 isTemp(3), g
.zNN
, g
.zPK
, g
.zNN
, g
.zNN
, g
.zWR
);
579 speedtest1_prepare("INSERT INTO t3 VALUES(?1,?2,?3); -- %d times", n
);
581 x1
= swizzle(i
,maxb
);
582 speedtest1_numbername(x1
, zNum
, sizeof(zNum
));
583 sqlite3_bind_int(g
.pStmt
, 2, i
);
584 sqlite3_bind_int64(g
.pStmt
, 1, (sqlite3_int64
)x1
);
585 sqlite3_bind_text(g
.pStmt
, 3, zNum
, -1, SQLITE_STATIC
);
588 speedtest1_exec("COMMIT");
589 speedtest1_end_test();
591 #if SQLITE_VERSION_NUMBER<3005004
592 sqlite3_create_function(g
.db
, "group_concat", 1, SQLITE_UTF8
, 0,
593 0, groupStep
, groupFinal
);
597 speedtest1_begin_test(130, "%d SELECTS, numeric BETWEEN, unindexed", n
);
598 speedtest1_exec("BEGIN");
600 "SELECT count(*), avg(b), sum(length(c)), group_concat(c) FROM t1\n"
601 " WHERE b BETWEEN ?1 AND ?2; -- %d times", n
604 if( (i
-1)%g
.nRepeat
==0 ){
605 x1
= speedtest1_random()%maxb
;
606 x2
= speedtest1_random()%10 + sz
/5000 + x1
;
608 sqlite3_bind_int(g
.pStmt
, 1, x1
);
609 sqlite3_bind_int(g
.pStmt
, 2, x2
);
612 speedtest1_exec("COMMIT");
613 speedtest1_end_test();
617 speedtest1_begin_test(140, "%d SELECTS, LIKE, unindexed", n
);
618 speedtest1_exec("BEGIN");
620 "SELECT count(*), avg(b), sum(length(c)), group_concat(c) FROM t1\n"
621 " WHERE c LIKE ?1; -- %d times", n
624 if( (i
-1)%g
.nRepeat
==0 ){
625 x1
= speedtest1_random()%maxb
;
627 len
= speedtest1_numbername(i
, zNum
+1, sizeof(zNum
)-2);
631 sqlite3_bind_text(g
.pStmt
, 1, zNum
, len
+1, SQLITE_STATIC
);
634 speedtest1_exec("COMMIT");
635 speedtest1_end_test();
639 speedtest1_begin_test(142, "%d SELECTS w/ORDER BY, unindexed", n
);
640 speedtest1_exec("BEGIN");
642 "SELECT a, b, c FROM t1 WHERE c LIKE ?1\n"
643 " ORDER BY a; -- %d times", n
646 if( (i
-1)%g
.nRepeat
==0 ){
647 x1
= speedtest1_random()%maxb
;
649 len
= speedtest1_numbername(i
, zNum
+1, sizeof(zNum
)-2);
653 sqlite3_bind_text(g
.pStmt
, 1, zNum
, len
+1, SQLITE_STATIC
);
656 speedtest1_exec("COMMIT");
657 speedtest1_end_test();
659 n
= 10; /* g.szTest/5; */
660 speedtest1_begin_test(145, "%d SELECTS w/ORDER BY and LIMIT, unindexed", n
);
661 speedtest1_exec("BEGIN");
663 "SELECT a, b, c FROM t1 WHERE c LIKE ?1\n"
664 " ORDER BY a LIMIT 10; -- %d times", n
667 if( (i
-1)%g
.nRepeat
==0 ){
668 x1
= speedtest1_random()%maxb
;
670 len
= speedtest1_numbername(i
, zNum
+1, sizeof(zNum
)-2);
674 sqlite3_bind_text(g
.pStmt
, 1, zNum
, len
+1, SQLITE_STATIC
);
677 speedtest1_exec("COMMIT");
678 speedtest1_end_test();
681 speedtest1_begin_test(150, "CREATE INDEX five times");
682 speedtest1_exec("BEGIN;");
683 speedtest1_exec("CREATE UNIQUE INDEX t1b ON t1(b);");
684 speedtest1_exec("CREATE INDEX t1c ON t1(c);");
685 speedtest1_exec("CREATE UNIQUE INDEX t2b ON t2(b);");
686 speedtest1_exec("CREATE INDEX t2c ON t2(c DESC);");
687 speedtest1_exec("CREATE INDEX t3bc ON t3(b,c);");
688 speedtest1_exec("COMMIT;");
689 speedtest1_end_test();
693 speedtest1_begin_test(160, "%d SELECTS, numeric BETWEEN, indexed", n
);
694 speedtest1_exec("BEGIN");
696 "SELECT count(*), avg(b), sum(length(c)), group_concat(a) FROM t1\n"
697 " WHERE b BETWEEN ?1 AND ?2; -- %d times", n
700 if( (i
-1)%g
.nRepeat
==0 ){
701 x1
= speedtest1_random()%maxb
;
702 x2
= speedtest1_random()%10 + sz
/5000 + x1
;
704 sqlite3_bind_int(g
.pStmt
, 1, x1
);
705 sqlite3_bind_int(g
.pStmt
, 2, x2
);
708 speedtest1_exec("COMMIT");
709 speedtest1_end_test();
713 speedtest1_begin_test(161, "%d SELECTS, numeric BETWEEN, PK", n
);
714 speedtest1_exec("BEGIN");
716 "SELECT count(*), avg(b), sum(length(c)), group_concat(a) FROM t2\n"
717 " WHERE a BETWEEN ?1 AND ?2; -- %d times", n
720 if( (i
-1)%g
.nRepeat
==0 ){
721 x1
= speedtest1_random()%maxb
;
722 x2
= speedtest1_random()%10 + sz
/5000 + x1
;
724 sqlite3_bind_int(g
.pStmt
, 1, x1
);
725 sqlite3_bind_int(g
.pStmt
, 2, x2
);
728 speedtest1_exec("COMMIT");
729 speedtest1_end_test();
733 speedtest1_begin_test(170, "%d SELECTS, text BETWEEN, indexed", n
);
734 speedtest1_exec("BEGIN");
736 "SELECT count(*), avg(b), sum(length(c)), group_concat(a) FROM t1\n"
737 " WHERE c BETWEEN ?1 AND (?1||'~'); -- %d times", n
740 if( (i
-1)%g
.nRepeat
==0 ){
741 x1
= swizzle(i
, maxb
);
742 len
= speedtest1_numbername(x1
, zNum
, sizeof(zNum
)-1);
744 sqlite3_bind_text(g
.pStmt
, 1, zNum
, len
, SQLITE_STATIC
);
747 speedtest1_exec("COMMIT");
748 speedtest1_end_test();
751 speedtest1_begin_test(180, "%d INSERTS with three indexes", n
);
752 speedtest1_exec("BEGIN");
754 "CREATE%s TABLE t4(\n"
755 " a INTEGER %s %s,\n"
759 isTemp(1), g
.zNN
, g
.zPK
, g
.zNN
, g
.zNN
, g
.zWR
);
760 speedtest1_exec("CREATE INDEX t4b ON t4(b)");
761 speedtest1_exec("CREATE INDEX t4c ON t4(c)");
762 speedtest1_exec("INSERT INTO t4 SELECT * FROM t1");
763 speedtest1_exec("COMMIT");
764 speedtest1_end_test();
767 speedtest1_begin_test(190, "DELETE and REFILL one table", n
);
768 speedtest1_exec("DELETE FROM t2;");
769 speedtest1_exec("INSERT INTO t2 SELECT * FROM t1;");
770 speedtest1_end_test();
773 speedtest1_begin_test(200, "VACUUM");
774 speedtest1_exec("VACUUM");
775 speedtest1_end_test();
778 speedtest1_begin_test(210, "ALTER TABLE ADD COLUMN, and query");
779 speedtest1_exec("ALTER TABLE t2 ADD COLUMN d DEFAULT 123");
780 speedtest1_exec("SELECT sum(d) FROM t2");
781 speedtest1_end_test();
785 speedtest1_begin_test(230, "%d UPDATES, numeric BETWEEN, indexed", n
);
786 speedtest1_exec("BEGIN");
788 "UPDATE t2 SET d=b*2 WHERE b BETWEEN ?1 AND ?2; -- %d times", n
791 x1
= speedtest1_random()%maxb
;
792 x2
= speedtest1_random()%10 + sz
/5000 + x1
;
793 sqlite3_bind_int(g
.pStmt
, 1, x1
);
794 sqlite3_bind_int(g
.pStmt
, 2, x2
);
797 speedtest1_exec("COMMIT");
798 speedtest1_end_test();
802 speedtest1_begin_test(240, "%d UPDATES of individual rows", n
);
803 speedtest1_exec("BEGIN");
805 "UPDATE t2 SET d=b*3 WHERE a=?1; -- %d times", n
808 x1
= speedtest1_random()%sz
+ 1;
809 sqlite3_bind_int(g
.pStmt
, 1, x1
);
812 speedtest1_exec("COMMIT");
813 speedtest1_end_test();
815 speedtest1_begin_test(250, "One big UPDATE of the whole %d-row table", sz
);
816 speedtest1_exec("UPDATE t2 SET d=b*4");
817 speedtest1_end_test();
820 speedtest1_begin_test(260, "Query added column after filling");
821 speedtest1_exec("SELECT sum(d) FROM t2");
822 speedtest1_end_test();
827 speedtest1_begin_test(270, "%d DELETEs, numeric BETWEEN, indexed", n
);
828 speedtest1_exec("BEGIN");
830 "DELETE FROM t2 WHERE b BETWEEN ?1 AND ?2; -- %d times", n
833 x1
= speedtest1_random()%maxb
+ 1;
834 x2
= speedtest1_random()%10 + sz
/5000 + x1
;
835 sqlite3_bind_int(g
.pStmt
, 1, x1
);
836 sqlite3_bind_int(g
.pStmt
, 2, x2
);
839 speedtest1_exec("COMMIT");
840 speedtest1_end_test();
844 speedtest1_begin_test(280, "%d DELETEs of individual rows", n
);
845 speedtest1_exec("BEGIN");
847 "DELETE FROM t3 WHERE a=?1; -- %d times", n
850 x1
= speedtest1_random()%sz
+ 1;
851 sqlite3_bind_int(g
.pStmt
, 1, x1
);
854 speedtest1_exec("COMMIT");
855 speedtest1_end_test();
858 speedtest1_begin_test(290, "Refill two %d-row tables using REPLACE", sz
);
859 speedtest1_exec("REPLACE INTO t2(a,b,c) SELECT a,b,c FROM t1");
860 speedtest1_exec("REPLACE INTO t3(a,b,c) SELECT a,b,c FROM t1");
861 speedtest1_end_test();
863 speedtest1_begin_test(300, "Refill a %d-row table using (b&1)==(a&1)", sz
);
864 speedtest1_exec("DELETE FROM t2;");
865 speedtest1_exec("INSERT INTO t2(a,b,c)\n"
866 " SELECT a,b,c FROM t1 WHERE (b&1)==(a&1);");
867 speedtest1_exec("INSERT INTO t2(a,b,c)\n"
868 " SELECT a,b,c FROM t1 WHERE (b&1)<>(a&1);");
869 speedtest1_end_test();
873 speedtest1_begin_test(310, "%d four-ways joins", n
);
874 speedtest1_exec("BEGIN");
876 "SELECT t1.c FROM t1, t2, t3, t4\n"
877 " WHERE t4.a BETWEEN ?1 AND ?2\n"
883 x1
= speedtest1_random()%sz
+ 1;
884 x2
= speedtest1_random()%10 + x1
+ 4;
885 sqlite3_bind_int(g
.pStmt
, 1, x1
);
886 sqlite3_bind_int(g
.pStmt
, 2, x2
);
889 speedtest1_exec("COMMIT");
890 speedtest1_end_test();
892 speedtest1_begin_test(320, "subquery in result set", n
);
894 "SELECT sum(a), max(c),\n"
895 " avg((SELECT a FROM t2 WHERE 5+t2.b=t1.b) AND rowid<?1), max(c)\n"
896 " FROM t1 WHERE rowid<?1;"
898 sqlite3_bind_int(g
.pStmt
, 1, est_square_root(g
.szTest
)*50);
900 speedtest1_end_test();
902 sz
= n
= g
.szTest
*700;
904 maxb
= roundup_allones(sz
/3);
905 speedtest1_begin_test(400, "%d REPLACE ops on an IPK", n
);
906 speedtest1_exec("BEGIN");
907 speedtest1_exec("CREATE%s TABLE t5(a INTEGER PRIMARY KEY, b %s);",
909 speedtest1_prepare("REPLACE INTO t5 VALUES(?1,?2); -- %d times",n
);
911 x1
= swizzle(i
,maxb
);
912 speedtest1_numbername(i
, zNum
, sizeof(zNum
));
913 sqlite3_bind_int(g
.pStmt
, 1, (sqlite3_int64
)x1
);
914 sqlite3_bind_text(g
.pStmt
, 2, zNum
, -1, SQLITE_STATIC
);
917 speedtest1_exec("COMMIT");
918 speedtest1_end_test();
919 speedtest1_begin_test(410, "%d SELECTS on an IPK", n
);
920 speedtest1_prepare("SELECT b FROM t5 WHERE a=?1; -- %d times",n
);
922 x1
= swizzle(i
,maxb
);
923 sqlite3_bind_int(g
.pStmt
, 1, (sqlite3_int64
)x1
);
926 speedtest1_end_test();
928 sz
= n
= g
.szTest
*700;
930 maxb
= roundup_allones(sz
/3);
931 speedtest1_begin_test(500, "%d REPLACE on TEXT PK", n
);
932 speedtest1_exec("BEGIN");
933 speedtest1_exec("CREATE%s TABLE t6(a TEXT PRIMARY KEY, b %s)%s;",
935 sqlite3_libversion_number()>=3008002 ? "WITHOUT ROWID" : "");
936 speedtest1_prepare("REPLACE INTO t6 VALUES(?1,?2); -- %d times",n
);
938 x1
= swizzle(i
,maxb
);
939 speedtest1_numbername(x1
, zNum
, sizeof(zNum
));
940 sqlite3_bind_int(g
.pStmt
, 2, i
);
941 sqlite3_bind_text(g
.pStmt
, 1, zNum
, -1, SQLITE_STATIC
);
944 speedtest1_exec("COMMIT");
945 speedtest1_end_test();
946 speedtest1_begin_test(510, "%d SELECTS on a TEXT PK", n
);
947 speedtest1_prepare("SELECT b FROM t6 WHERE a=?1; -- %d times",n
);
949 x1
= swizzle(i
,maxb
);
950 speedtest1_numbername(x1
, zNum
, sizeof(zNum
));
951 sqlite3_bind_text(g
.pStmt
, 1, zNum
, -1, SQLITE_STATIC
);
954 speedtest1_end_test();
955 speedtest1_begin_test(520, "%d SELECT DISTINCT", n
);
956 speedtest1_exec("SELECT DISTINCT b FROM t5;");
957 speedtest1_exec("SELECT DISTINCT b FROM t6;");
958 speedtest1_end_test();
961 speedtest1_begin_test(980, "PRAGMA integrity_check");
962 speedtest1_exec("PRAGMA integrity_check");
963 speedtest1_end_test();
966 speedtest1_begin_test(990, "ANALYZE");
967 speedtest1_exec("ANALYZE");
968 speedtest1_end_test();
972 ** A testset for common table expressions. This exercises code
973 ** for views, subqueries, co-routines, etc.
975 void testset_cte(void){
976 static const char *azPuzzle
[] = {
1016 }else if( g
.szTest
<70 ){
1021 speedtest1_begin_test(100, "Sudoku with recursive 'digits'");
1024 " input(sud) AS (VALUES(?1)),\n"
1025 " digits(z,lp) AS (\n"
1028 " SELECT CAST(lp+1 AS TEXT), lp+1 FROM digits WHERE lp<9\n"
1031 " SELECT sud, instr(sud, '.') FROM input\n"
1034 " substr(s, 1, ind-1) || z || substr(s, ind+1),\n"
1035 " instr( substr(s, 1, ind-1) || z || substr(s, ind+1), '.' )\n"
1036 " FROM x, digits AS z\n"
1038 " AND NOT EXISTS (\n"
1040 " FROM digits AS lp\n"
1041 " WHERE z.z = substr(s, ((ind-1)/9)*9 + lp, 1)\n"
1042 " OR z.z = substr(s, ((ind-1)%%9) + (lp-1)*9 + 1, 1)\n"
1043 " OR z.z = substr(s, (((ind-1)/3) %% 3) * 3\n"
1044 " + ((ind-1)/27) * 27 + lp\n"
1045 " + ((lp-1) / 3) * 6, 1)\n"
1048 "SELECT s FROM x WHERE ind=0;"
1050 sqlite3_bind_text(g
.pStmt
, 1, zPuz
, -1, SQLITE_STATIC
);
1052 speedtest1_end_test();
1054 speedtest1_begin_test(200, "Sudoku with VALUES 'digits'");
1057 " input(sud) AS (VALUES(?1)),\n"
1058 " digits(z,lp) AS (VALUES('1',1),('2',2),('3',3),('4',4),('5',5),\n"
1059 " ('6',6),('7',7),('8',8),('9',9)),\n"
1061 " SELECT sud, instr(sud, '.') FROM input\n"
1064 " substr(s, 1, ind-1) || z || substr(s, ind+1),\n"
1065 " instr( substr(s, 1, ind-1) || z || substr(s, ind+1), '.' )\n"
1066 " FROM x, digits AS z\n"
1068 " AND NOT EXISTS (\n"
1070 " FROM digits AS lp\n"
1071 " WHERE z.z = substr(s, ((ind-1)/9)*9 + lp, 1)\n"
1072 " OR z.z = substr(s, ((ind-1)%%9) + (lp-1)*9 + 1, 1)\n"
1073 " OR z.z = substr(s, (((ind-1)/3) %% 3) * 3\n"
1074 " + ((ind-1)/27) * 27 + lp\n"
1075 " + ((lp-1) / 3) * 6, 1)\n"
1078 "SELECT s FROM x WHERE ind=0;"
1080 sqlite3_bind_text(g
.pStmt
, 1, zPuz
, -1, SQLITE_STATIC
);
1082 speedtest1_end_test();
1084 rSpacing
= 5.0/g
.szTest
;
1085 speedtest1_begin_test(300, "Mandelbrot Set with spacing=%f", rSpacing
);
1088 " xaxis(x) AS (VALUES(-2.0) UNION ALL SELECT x+?1 FROM xaxis WHERE x<1.2),\n"
1089 " yaxis(y) AS (VALUES(-1.0) UNION ALL SELECT y+?2 FROM yaxis WHERE y<1.0),\n"
1090 " m(iter, cx, cy, x, y) AS (\n"
1091 " SELECT 0, x, y, 0.0, 0.0 FROM xaxis, yaxis\n"
1093 " SELECT iter+1, cx, cy, x*x-y*y + cx, 2.0*x*y + cy FROM m \n"
1094 " WHERE (x*x + y*y) < 4.0 AND iter<28\n"
1096 " m2(iter, cx, cy) AS (\n"
1097 " SELECT max(iter), cx, cy FROM m GROUP BY cx, cy\n"
1100 " SELECT group_concat( substr(' .+*#', 1+min(iter/7,4), 1), '') \n"
1101 " FROM m2 GROUP BY cy\n"
1103 "SELECT group_concat(rtrim(t),x'0a') FROM a;"
1105 sqlite3_bind_double(g
.pStmt
, 1, rSpacing
*.05);
1106 sqlite3_bind_double(g
.pStmt
, 2, rSpacing
);
1108 speedtest1_end_test();
1110 nElem
= 10000*g
.szTest
;
1111 speedtest1_begin_test(400, "EXCEPT operator on %d-element tables", nElem
);
1114 " t1(x) AS (VALUES(2) UNION ALL SELECT x+2 FROM t1 WHERE x<%d),\n"
1115 " t2(y) AS (VALUES(3) UNION ALL SELECT y+3 FROM t2 WHERE y<%d)\n"
1116 "SELECT count(x), avg(x) FROM (\n"
1117 " SELECT x FROM t1 EXCEPT SELECT y FROM t2 ORDER BY 1\n"
1122 speedtest1_end_test();
1126 #ifdef SQLITE_ENABLE_RTREE
1127 /* Generate two numbers between 1 and mx. The first number is less than
1128 ** the second. Usually the numbers are near each other but can sometimes
1131 static void twoCoords(
1132 int p1
, int p2
, /* Parameters adjusting sizes */
1133 unsigned mx
, /* Range of 1..mx */
1134 unsigned *pX0
, unsigned *pX1
/* OUT: write results here */
1136 unsigned d
, x0
, x1
, span
;
1139 if( speedtest1_random()%3==0 ) span
*= p1
;
1140 if( speedtest1_random()%p2
==0 ) span
= mx
/2;
1141 d
= speedtest1_random()%span
+ 1;
1142 x0
= speedtest1_random()%(mx
-d
) + 1;
1149 #ifdef SQLITE_ENABLE_RTREE
1150 /* The following routine is an R-Tree geometry callback. It returns
1151 ** true if the object overlaps a slice on the Y coordinate between the
1152 ** two values given as arguments. In other words
1154 ** SELECT count(*) FROM rt1 WHERE id MATCH xslice(10,20);
1156 ** Is the same as saying:
1158 ** SELECT count(*) FROM rt1 WHERE y1>=10 AND y0<=20;
1160 static int xsliceGeometryCallback(
1161 sqlite3_rtree_geometry
*p
,
1166 *pRes
= aCoord
[3]>=p
->aParam
[0] && aCoord
[2]<=p
->aParam
[1];
1169 #endif /* SQLITE_ENABLE_RTREE */
1171 #ifdef SQLITE_ENABLE_RTREE
1173 ** A testset for the R-Tree virtual table
1175 void testset_rtree(int p1
, int p2
){
1178 unsigned x0
, x1
, y0
, y1
, z0
, z1
;
1180 int *aCheck
= sqlite3_malloc( sizeof(int)*g
.szTest
*500 );
1184 speedtest1_begin_test(100, "%d INSERTs into an r-tree", n
);
1185 speedtest1_exec("BEGIN");
1186 speedtest1_exec("CREATE VIRTUAL TABLE rt1 USING rtree(id,x0,x1,y0,y1,z0,z1)");
1187 speedtest1_prepare("INSERT INTO rt1(id,x0,x1,y0,y1,z0,z1)"
1188 "VALUES(?1,?2,?3,?4,?5,?6,?7)");
1189 for(i
=1; i
<=n
; i
++){
1190 twoCoords(p1
, p2
, mxCoord
, &x0
, &x1
);
1191 twoCoords(p1
, p2
, mxCoord
, &y0
, &y1
);
1192 twoCoords(p1
, p2
, mxCoord
, &z0
, &z1
);
1193 sqlite3_bind_int(g
.pStmt
, 1, i
);
1194 sqlite3_bind_int(g
.pStmt
, 2, x0
);
1195 sqlite3_bind_int(g
.pStmt
, 3, x1
);
1196 sqlite3_bind_int(g
.pStmt
, 4, y0
);
1197 sqlite3_bind_int(g
.pStmt
, 5, y1
);
1198 sqlite3_bind_int(g
.pStmt
, 6, z0
);
1199 sqlite3_bind_int(g
.pStmt
, 7, z1
);
1202 speedtest1_exec("COMMIT");
1203 speedtest1_end_test();
1205 speedtest1_begin_test(101, "Copy from rtree to a regular table");
1206 speedtest1_exec("CREATE TABLE t1(id INTEGER PRIMARY KEY,x0,x1,y0,y1,z0,z1)");
1207 speedtest1_exec("INSERT INTO t1 SELECT * FROM rt1");
1208 speedtest1_end_test();
1211 speedtest1_begin_test(110, "%d one-dimensional intersect slice queries", n
);
1212 speedtest1_prepare("SELECT count(*) FROM rt1 WHERE x0>=?1 AND x1<=?2");
1215 sqlite3_bind_int(g
.pStmt
, 1, i
*iStep
);
1216 sqlite3_bind_int(g
.pStmt
, 2, (i
+1)*iStep
);
1218 aCheck
[i
] = atoi(g
.zResult
);
1220 speedtest1_end_test();
1224 speedtest1_begin_test(111, "Verify result from 1-D intersect slice queries");
1225 speedtest1_prepare("SELECT count(*) FROM t1 WHERE x0>=?1 AND x1<=?2");
1228 sqlite3_bind_int(g
.pStmt
, 1, i
*iStep
);
1229 sqlite3_bind_int(g
.pStmt
, 2, (i
+1)*iStep
);
1231 if( aCheck
[i
]!=atoi(g
.zResult
) ){
1232 fatal_error("Count disagree step %d: %d..%d. %d vs %d",
1233 i
, i
*iStep
, (i
+1)*iStep
, aCheck
[i
], atoi(g
.zResult
));
1236 speedtest1_end_test();
1240 speedtest1_begin_test(120, "%d one-dimensional overlap slice queries", n
);
1241 speedtest1_prepare("SELECT count(*) FROM rt1 WHERE y1>=?1 AND y0<=?2");
1244 sqlite3_bind_int(g
.pStmt
, 1, i
*iStep
);
1245 sqlite3_bind_int(g
.pStmt
, 2, (i
+1)*iStep
);
1247 aCheck
[i
] = atoi(g
.zResult
);
1249 speedtest1_end_test();
1253 speedtest1_begin_test(121, "Verify result from 1-D overlap slice queries");
1254 speedtest1_prepare("SELECT count(*) FROM t1 WHERE y1>=?1 AND y0<=?2");
1257 sqlite3_bind_int(g
.pStmt
, 1, i
*iStep
);
1258 sqlite3_bind_int(g
.pStmt
, 2, (i
+1)*iStep
);
1260 if( aCheck
[i
]!=atoi(g
.zResult
) ){
1261 fatal_error("Count disagree step %d: %d..%d. %d vs %d",
1262 i
, i
*iStep
, (i
+1)*iStep
, aCheck
[i
], atoi(g
.zResult
));
1265 speedtest1_end_test();
1270 speedtest1_begin_test(125, "%d custom geometry callback queries", n
);
1271 sqlite3_rtree_geometry_callback(g
.db
, "xslice", xsliceGeometryCallback
, 0);
1272 speedtest1_prepare("SELECT count(*) FROM rt1 WHERE id MATCH xslice(?1,?2)");
1275 sqlite3_bind_int(g
.pStmt
, 1, i
*iStep
);
1276 sqlite3_bind_int(g
.pStmt
, 2, (i
+1)*iStep
);
1278 if( aCheck
[i
]!=atoi(g
.zResult
) ){
1279 fatal_error("Count disagree step %d: %d..%d. %d vs %d",
1280 i
, i
*iStep
, (i
+1)*iStep
, aCheck
[i
], atoi(g
.zResult
));
1283 speedtest1_end_test();
1286 speedtest1_begin_test(130, "%d three-dimensional intersect box queries", n
);
1287 speedtest1_prepare("SELECT count(*) FROM rt1 WHERE x1>=?1 AND x0<=?2"
1288 " AND y1>=?1 AND y0<=?2 AND z1>=?1 AND z0<=?2");
1291 sqlite3_bind_int(g
.pStmt
, 1, i
*iStep
);
1292 sqlite3_bind_int(g
.pStmt
, 2, (i
+1)*iStep
);
1294 aCheck
[i
] = atoi(g
.zResult
);
1296 speedtest1_end_test();
1299 speedtest1_begin_test(140, "%d rowid queries", n
);
1300 speedtest1_prepare("SELECT * FROM rt1 WHERE id=?1");
1301 for(i
=1; i
<=n
; i
++){
1302 sqlite3_bind_int(g
.pStmt
, 1, i
);
1305 speedtest1_end_test();
1307 #endif /* SQLITE_ENABLE_RTREE */
1310 ** A testset that does key/value storage on tables with many columns.
1311 ** This is the kind of workload generated by ORMs such as CoreData.
1313 void testset_orm(void){
1317 char zNum
[2000]; /* A number name */
1318 static const char zType
[] = /* Types for all non-PK columns, in order */
1319 "IBBIIITIVVITBTBFBFITTFBTBVBVIFTBBFITFFVBIFIVBVVVBTVTIBBFFIVIBTB"
1320 "TVTTFTVTVFFIITIFBITFTTFFFVBIIBTTITFTFFVVVFIIITVBBVFFTVVB";
1322 nRow
= n
= g
.szTest
*250;
1323 speedtest1_begin_test(100, "Fill %d rows", n
);
1326 "CREATE TABLE ZLOOKSLIKECOREDATA ("
1327 " ZPK INTEGER PRIMARY KEY,"
1328 " ZTERMFITTINGHOUSINGCOMMAND INTEGER,"
1329 " ZBRIEFGOBYDODGERHEIGHT BLOB,"
1330 " ZCAPABLETRIPDOORALMOND BLOB,"
1331 " ZDEPOSITPAIRCOLLEGECOMET INTEGER,"
1332 " ZFRAMEENTERSIMPLEMOUTH INTEGER,"
1333 " ZHOPEFULGATEHOLECHALK INTEGER,"
1334 " ZSLEEPYUSERGRANDBOWL TIMESTAMP,"
1335 " ZDEWPEACHCAREERCELERY INTEGER,"
1336 " ZHANGERLITHIUMDINNERMEET VARCHAR,"
1337 " ZCLUBRELEASELIZARDADVICE VARCHAR,"
1338 " ZCHARGECLICKHUMANEHIRE INTEGER,"
1339 " ZFINGERDUEPIZZAOPTION TIMESTAMP,"
1340 " ZFLYINGDOCTORTABLEMELODY BLOB,"
1341 " ZLONGFINLEAVEIMAGEOIL TIMESTAMP,"
1342 " ZFAMILYVISUALOWNERMATTER BLOB,"
1343 " ZGOLDYOUNGINITIALNOSE FLOAT,"
1344 " ZCAUSESALAMITERMCYAN BLOB,"
1345 " ZSPREADMOTORBISCUITBACON FLOAT,"
1346 " ZGIFTICEFISHGLUEHAIR INTEGER,"
1347 " ZNOTICEPEARPOLICYJUICE TIMESTAMP,"
1348 " ZBANKBUFFALORECOVERORBIT TIMESTAMP,"
1349 " ZLONGDIETESSAYNATURE FLOAT,"
1350 " ZACTIONRANGEELEGANTNEUTRON BLOB,"
1351 " ZCADETBRIGHTPLANETBANK TIMESTAMP,"
1352 " ZAIRFORGIVEHEADFROG BLOB,"
1353 " ZSHARKJUSTFRUITMOVIE VARCHAR,"
1354 " ZFARMERMORNINGMIRRORCONCERN BLOB,"
1355 " ZWOODPOETRYCOBBLERBENCH VARCHAR,"
1356 " ZHAFNIUMSCRIPTSALADMOTOR INTEGER,"
1357 " ZPROBLEMCLUBPOPOVERJELLY FLOAT,"
1358 " ZEIGHTLEADERWORKERMOST TIMESTAMP,"
1359 " ZGLASSRESERVEBARIUMMEAL BLOB,"
1360 " ZCLAMBITARUGULAFAJITA BLOB,"
1361 " ZDECADEJOYOUSWAVEHABIT FLOAT,"
1362 " ZCOMPANYSUMMERFIBERELF INTEGER,"
1363 " ZTREATTESTQUILLCHARGE TIMESTAMP,"
1364 " ZBROWBALANCEKEYCHOWDER FLOAT,"
1365 " ZPEACHCOPPERDINNERLAKE FLOAT,"
1366 " ZDRYWALLBEYONDBROWNBOWL VARCHAR,"
1367 " ZBELLYCRASHITEMLACK BLOB,"
1368 " ZTENNISCYCLEBILLOFFICER INTEGER,"
1369 " ZMALLEQUIPTHANKSGLUE FLOAT,"
1370 " ZMISSREPLYHUMANLIVING INTEGER,"
1371 " ZKIWIVISUALPRIDEAPPLE VARCHAR,"
1372 " ZWISHHITSKINMOTOR BLOB,"
1373 " ZCALMRACCOONPROGRAMDEBIT VARCHAR,"
1374 " ZSHINYASSISTLIVINGCRAB VARCHAR,"
1375 " ZRESOLVEWRISTWRAPAPPLE VARCHAR,"
1376 " ZAPPEALSIMPLESECONDHOUSING BLOB,"
1377 " ZCORNERANCHORTAPEDIVER TIMESTAMP,"
1378 " ZMEMORYREQUESTSOURCEBIG VARCHAR,"
1379 " ZTRYFACTKEEPMILK TIMESTAMP,"
1380 " ZDIVERPAINTLEATHEREASY INTEGER,"
1381 " ZSORTMISTYQUOTECABBAGE BLOB,"
1382 " ZTUNEGASBUFFALOCAPITAL BLOB,"
1383 " ZFILLSTOPLAWJOYFUL FLOAT,"
1384 " ZSTEELCAREFULPLATENUMBER FLOAT,"
1385 " ZGIVEVIVIDDIVINEMEANING INTEGER,"
1386 " ZTREATPACKFUTURECONVERT VARCHAR,"
1387 " ZCALMLYGEMFINISHEFFECT INTEGER,"
1388 " ZCABBAGESOCKEASEMINUTE BLOB,"
1389 " ZPLANETFAMILYPUREMEMORY TIMESTAMP,"
1390 " ZMERRYCRACKTRAINLEADER BLOB,"
1391 " ZMINORWAYPAPERCLASSY TIMESTAMP,"
1392 " ZEAGLELINEMINEMAIL VARCHAR,"
1393 " ZRESORTYARDGREENLET TIMESTAMP,"
1394 " ZYARDOREGANOVIVIDJEWEL TIMESTAMP,"
1395 " ZPURECAKEVIVIDNEATLY FLOAT,"
1396 " ZASKCONTACTMONITORFUN TIMESTAMP,"
1397 " ZMOVEWHOGAMMAINCH VARCHAR,"
1398 " ZLETTUCEBIRDMEETDEBATE TIMESTAMP,"
1399 " ZGENENATURALHEARINGKITE VARCHAR,"
1400 " ZMUFFINDRYERDRAWFORTUNE FLOAT,"
1401 " ZGRAYSURVEYWIRELOVE FLOAT,"
1402 " ZPLIERSPRINTASKOREGANO INTEGER,"
1403 " ZTRAVELDRIVERCONTESTLILY INTEGER,"
1404 " ZHUMORSPICESANDKIDNEY TIMESTAMP,"
1405 " ZARSENICSAMPLEWAITMUON INTEGER,"
1406 " ZLACEADDRESSGROUNDCAREFUL FLOAT,"
1407 " ZBAMBOOMESSWASABIEVENING BLOB,"
1408 " ZONERELEASEAVERAGENURSE INTEGER,"
1409 " ZRADIANTWHENTRYCARD TIMESTAMP,"
1410 " ZREWARDINSIDEMANGOINTENSE FLOAT,"
1411 " ZNEATSTEWPARTIRON TIMESTAMP,"
1412 " ZOUTSIDEPEAHENCOUNTICE TIMESTAMP,"
1413 " ZCREAMEVENINGLIPBRANCH FLOAT,"
1414 " ZWHALEMATHAVOCADOCOPPER FLOAT,"
1415 " ZLIFEUSELEAFYBELL FLOAT,"
1416 " ZWEALTHLINENGLEEFULDAY VARCHAR,"
1417 " ZFACEINVITETALKGOLD BLOB,"
1418 " ZWESTAMOUNTAFFECTHEARING INTEGER,"
1419 " ZDELAYOUTCOMEHORNAGENCY INTEGER,"
1420 " ZBIGTHINKCONVERTECONOMY BLOB,"
1421 " ZBASEGOUDAREGULARFORGIVE TIMESTAMP,"
1422 " ZPATTERNCLORINEGRANDCOLBY TIMESTAMP,"
1423 " ZCYANBASEFEEDADROIT INTEGER,"
1424 " ZCARRYFLOORMINNOWDRAGON TIMESTAMP,"
1425 " ZIMAGEPENCILOTHERBOTTOM FLOAT,"
1426 " ZXENONFLIGHTPALEAPPLE TIMESTAMP,"
1427 " ZHERRINGJOKEFEATUREHOPEFUL FLOAT,"
1428 " ZCAPYEARLYRIVETBRUSH FLOAT,"
1429 " ZAGEREEDFROGBASKET VARCHAR,"
1430 " ZUSUALBODYHALIBUTDIAMOND VARCHAR,"
1431 " ZFOOTTAPWORDENTRY VARCHAR,"
1432 " ZDISHKEEPBLESTMONITOR FLOAT,"
1433 " ZBROADABLESOLIDCASUAL INTEGER,"
1434 " ZSQUAREGLEEFULCHILDLIGHT INTEGER,"
1435 " ZHOLIDAYHEADPONYDETAIL INTEGER,"
1436 " ZGENERALRESORTSKYOPEN TIMESTAMP,"
1437 " ZGLADSPRAYKIDNEYGUPPY VARCHAR,"
1438 " ZSWIMHEAVYMENTIONKIND BLOB,"
1439 " ZMESSYSULFURDREAMFESTIVE BLOB,"
1440 " ZSKYSKYCLASSICBRIEF VARCHAR,"
1441 " ZDILLASKHOKILEMON FLOAT,"
1442 " ZJUNIORSHOWPRESSNOVA FLOAT,"
1443 " ZSIZETOEAWARDFRESH TIMESTAMP,"
1444 " ZKEYFAILAPRICOTMETAL VARCHAR,"
1445 " ZHANDYREPAIRPROTONAIRPORT VARCHAR,"
1446 " ZPOSTPROTEINHANDLEACTOR BLOB"
1450 "INSERT INTO ZLOOKSLIKECOREDATA(ZPK,ZAIRFORGIVEHEADFROG,"
1451 "ZGIFTICEFISHGLUEHAIR,ZDELAYOUTCOMEHORNAGENCY,ZSLEEPYUSERGRANDBOWL,"
1452 "ZGLASSRESERVEBARIUMMEAL,ZBRIEFGOBYDODGERHEIGHT,"
1453 "ZBAMBOOMESSWASABIEVENING,ZFARMERMORNINGMIRRORCONCERN,"
1454 "ZTREATPACKFUTURECONVERT,ZCAUSESALAMITERMCYAN,ZCALMRACCOONPROGRAMDEBIT,"
1455 "ZHOLIDAYHEADPONYDETAIL,ZWOODPOETRYCOBBLERBENCH,ZHAFNIUMSCRIPTSALADMOTOR,"
1456 "ZUSUALBODYHALIBUTDIAMOND,ZOUTSIDEPEAHENCOUNTICE,ZDIVERPAINTLEATHEREASY,"
1457 "ZWESTAMOUNTAFFECTHEARING,ZSIZETOEAWARDFRESH,ZDEWPEACHCAREERCELERY,"
1458 "ZSTEELCAREFULPLATENUMBER,ZCYANBASEFEEDADROIT,ZCALMLYGEMFINISHEFFECT,"
1459 "ZHANDYREPAIRPROTONAIRPORT,ZGENENATURALHEARINGKITE,ZBROADABLESOLIDCASUAL,"
1460 "ZPOSTPROTEINHANDLEACTOR,ZLACEADDRESSGROUNDCAREFUL,ZIMAGEPENCILOTHERBOTTOM,"
1461 "ZPROBLEMCLUBPOPOVERJELLY,ZPATTERNCLORINEGRANDCOLBY,ZNEATSTEWPARTIRON,"
1462 "ZAPPEALSIMPLESECONDHOUSING,ZMOVEWHOGAMMAINCH,ZTENNISCYCLEBILLOFFICER,"
1463 "ZSHARKJUSTFRUITMOVIE,ZKEYFAILAPRICOTMETAL,ZCOMPANYSUMMERFIBERELF,"
1464 "ZTERMFITTINGHOUSINGCOMMAND,ZRESORTYARDGREENLET,ZCABBAGESOCKEASEMINUTE,"
1465 "ZSQUAREGLEEFULCHILDLIGHT,ZONERELEASEAVERAGENURSE,ZBIGTHINKCONVERTECONOMY,"
1466 "ZPLIERSPRINTASKOREGANO,ZDECADEJOYOUSWAVEHABIT,ZDRYWALLBEYONDBROWNBOWL,"
1467 "ZCLUBRELEASELIZARDADVICE,ZWHALEMATHAVOCADOCOPPER,ZBELLYCRASHITEMLACK,"
1468 "ZLETTUCEBIRDMEETDEBATE,ZCAPABLETRIPDOORALMOND,ZRADIANTWHENTRYCARD,"
1469 "ZCAPYEARLYRIVETBRUSH,ZAGEREEDFROGBASKET,ZSWIMHEAVYMENTIONKIND,"
1470 "ZTRAVELDRIVERCONTESTLILY,ZGLADSPRAYKIDNEYGUPPY,ZBANKBUFFALORECOVERORBIT,"
1471 "ZFINGERDUEPIZZAOPTION,ZCLAMBITARUGULAFAJITA,ZLONGFINLEAVEIMAGEOIL,"
1472 "ZLONGDIETESSAYNATURE,ZJUNIORSHOWPRESSNOVA,ZHOPEFULGATEHOLECHALK,"
1473 "ZDEPOSITPAIRCOLLEGECOMET,ZWEALTHLINENGLEEFULDAY,ZFILLSTOPLAWJOYFUL,"
1474 "ZTUNEGASBUFFALOCAPITAL,ZGRAYSURVEYWIRELOVE,ZCORNERANCHORTAPEDIVER,"
1475 "ZREWARDINSIDEMANGOINTENSE,ZCADETBRIGHTPLANETBANK,ZPLANETFAMILYPUREMEMORY,"
1476 "ZTREATTESTQUILLCHARGE,ZCREAMEVENINGLIPBRANCH,ZSKYSKYCLASSICBRIEF,"
1477 "ZARSENICSAMPLEWAITMUON,ZBROWBALANCEKEYCHOWDER,ZFLYINGDOCTORTABLEMELODY,"
1478 "ZHANGERLITHIUMDINNERMEET,ZNOTICEPEARPOLICYJUICE,ZSHINYASSISTLIVINGCRAB,"
1479 "ZLIFEUSELEAFYBELL,ZFACEINVITETALKGOLD,ZGENERALRESORTSKYOPEN,"
1480 "ZPURECAKEVIVIDNEATLY,ZKIWIVISUALPRIDEAPPLE,ZMESSYSULFURDREAMFESTIVE,"
1481 "ZCHARGECLICKHUMANEHIRE,ZHERRINGJOKEFEATUREHOPEFUL,ZYARDOREGANOVIVIDJEWEL,"
1482 "ZFOOTTAPWORDENTRY,ZWISHHITSKINMOTOR,ZBASEGOUDAREGULARFORGIVE,"
1483 "ZMUFFINDRYERDRAWFORTUNE,ZACTIONRANGEELEGANTNEUTRON,ZTRYFACTKEEPMILK,"
1484 "ZPEACHCOPPERDINNERLAKE,ZFRAMEENTERSIMPLEMOUTH,ZMERRYCRACKTRAINLEADER,"
1485 "ZMEMORYREQUESTSOURCEBIG,ZCARRYFLOORMINNOWDRAGON,ZMINORWAYPAPERCLASSY,"
1486 "ZDILLASKHOKILEMON,ZRESOLVEWRISTWRAPAPPLE,ZASKCONTACTMONITORFUN,"
1487 "ZGIVEVIVIDDIVINEMEANING,ZEIGHTLEADERWORKERMOST,ZMISSREPLYHUMANLIVING,"
1488 "ZXENONFLIGHTPALEAPPLE,ZSORTMISTYQUOTECABBAGE,ZEAGLELINEMINEMAIL,"
1489 "ZFAMILYVISUALOWNERMATTER,ZSPREADMOTORBISCUITBACON,ZDISHKEEPBLESTMONITOR,"
1490 "ZMALLEQUIPTHANKSGLUE,ZGOLDYOUNGINITIALNOSE,ZHUMORSPICESANDKIDNEY)"
1491 "VALUES(?1,?26,?20,?93,?8,?33,?3,?81,?28,?60,?18,?47,?109,?29,?30,?104,?86,"
1492 "?54,?92,?117,?9,?58,?97,?61,?119,?73,?107,?120,?80,?99,?31,?96,?85,?50,?71,"
1493 "?42,?27,?118,?36,?2,?67,?62,?108,?82,?94,?76,?35,?40,?11,?88,?41,?72,?4,"
1494 "?83,?102,?103,?112,?77,?111,?22,?13,?34,?15,?23,?116,?7,?5,?90,?57,?56,"
1495 "?75,?51,?84,?25,?63,?37,?87,?114,?79,?38,?14,?10,?21,?48,?89,?91,?110,"
1496 "?69,?45,?113,?12,?101,?68,?105,?46,?95,?74,?24,?53,?39,?6,?64,?52,?98,"
1497 "?65,?115,?49,?70,?59,?32,?44,?100,?55,?66,?16,?19,?106,?43,?17,?78);"
1500 x1
= speedtest1_random();
1501 speedtest1_numbername(x1
%1000, zNum
, sizeof(zNum
));
1502 len
= (int)strlen(zNum
);
1503 sqlite3_bind_int(g
.pStmt
, 1, i
^0xf);
1504 for(j
=0; zType
[j
]; j
++){
1508 sqlite3_bind_int64(g
.pStmt
, j
+2, x1
);
1511 sqlite3_bind_double(g
.pStmt
, j
+2, (double)x1
);
1515 sqlite3_bind_text64(g
.pStmt
, j
+2, zNum
, len
,
1516 SQLITE_STATIC
, SQLITE_UTF8
);
1522 speedtest1_exec("COMMIT;");
1523 speedtest1_end_test();
1526 speedtest1_begin_test(110, "Query %d rows by rowid", n
);
1528 "SELECT ZCYANBASEFEEDADROIT,ZJUNIORSHOWPRESSNOVA,ZCAUSESALAMITERMCYAN,"
1529 "ZHOPEFULGATEHOLECHALK,ZHUMORSPICESANDKIDNEY,ZSWIMHEAVYMENTIONKIND,"
1530 "ZMOVEWHOGAMMAINCH,ZAPPEALSIMPLESECONDHOUSING,ZHAFNIUMSCRIPTSALADMOTOR,"
1531 "ZNEATSTEWPARTIRON,ZLONGFINLEAVEIMAGEOIL,ZDEWPEACHCAREERCELERY,"
1532 "ZXENONFLIGHTPALEAPPLE,ZCALMRACCOONPROGRAMDEBIT,ZUSUALBODYHALIBUTDIAMOND,"
1533 "ZTRYFACTKEEPMILK,ZWEALTHLINENGLEEFULDAY,ZLONGDIETESSAYNATURE,"
1534 "ZLIFEUSELEAFYBELL,ZTREATPACKFUTURECONVERT,ZMEMORYREQUESTSOURCEBIG,"
1535 "ZYARDOREGANOVIVIDJEWEL,ZDEPOSITPAIRCOLLEGECOMET,ZSLEEPYUSERGRANDBOWL,"
1536 "ZBRIEFGOBYDODGERHEIGHT,ZCLUBRELEASELIZARDADVICE,ZCAPABLETRIPDOORALMOND,"
1537 "ZDRYWALLBEYONDBROWNBOWL,ZASKCONTACTMONITORFUN,ZKIWIVISUALPRIDEAPPLE,"
1538 "ZNOTICEPEARPOLICYJUICE,ZPEACHCOPPERDINNERLAKE,ZSTEELCAREFULPLATENUMBER,"
1539 "ZGLADSPRAYKIDNEYGUPPY,ZCOMPANYSUMMERFIBERELF,ZTENNISCYCLEBILLOFFICER,"
1540 "ZIMAGEPENCILOTHERBOTTOM,ZWESTAMOUNTAFFECTHEARING,ZDIVERPAINTLEATHEREASY,"
1541 "ZSKYSKYCLASSICBRIEF,ZMESSYSULFURDREAMFESTIVE,ZMERRYCRACKTRAINLEADER,"
1542 "ZBROADABLESOLIDCASUAL,ZGLASSRESERVEBARIUMMEAL,ZTUNEGASBUFFALOCAPITAL,"
1543 "ZBANKBUFFALORECOVERORBIT,ZTREATTESTQUILLCHARGE,ZBAMBOOMESSWASABIEVENING,"
1544 "ZREWARDINSIDEMANGOINTENSE,ZEAGLELINEMINEMAIL,ZCALMLYGEMFINISHEFFECT,"
1545 "ZKEYFAILAPRICOTMETAL,ZFINGERDUEPIZZAOPTION,ZCADETBRIGHTPLANETBANK,"
1546 "ZGOLDYOUNGINITIALNOSE,ZMISSREPLYHUMANLIVING,ZEIGHTLEADERWORKERMOST,"
1547 "ZFRAMEENTERSIMPLEMOUTH,ZBIGTHINKCONVERTECONOMY,ZFACEINVITETALKGOLD,"
1548 "ZPOSTPROTEINHANDLEACTOR,ZHERRINGJOKEFEATUREHOPEFUL,ZCABBAGESOCKEASEMINUTE,"
1549 "ZMUFFINDRYERDRAWFORTUNE,ZPROBLEMCLUBPOPOVERJELLY,ZGIVEVIVIDDIVINEMEANING,"
1550 "ZGENENATURALHEARINGKITE,ZGENERALRESORTSKYOPEN,ZLETTUCEBIRDMEETDEBATE,"
1551 "ZBASEGOUDAREGULARFORGIVE,ZCHARGECLICKHUMANEHIRE,ZPLANETFAMILYPUREMEMORY,"
1552 "ZMINORWAYPAPERCLASSY,ZCAPYEARLYRIVETBRUSH,ZSIZETOEAWARDFRESH,"
1553 "ZARSENICSAMPLEWAITMUON,ZSQUAREGLEEFULCHILDLIGHT,ZSHINYASSISTLIVINGCRAB,"
1554 "ZCORNERANCHORTAPEDIVER,ZDECADEJOYOUSWAVEHABIT,ZTRAVELDRIVERCONTESTLILY,"
1555 "ZFLYINGDOCTORTABLEMELODY,ZSHARKJUSTFRUITMOVIE,ZFAMILYVISUALOWNERMATTER,"
1556 "ZFARMERMORNINGMIRRORCONCERN,ZGIFTICEFISHGLUEHAIR,ZOUTSIDEPEAHENCOUNTICE,"
1557 "ZSPREADMOTORBISCUITBACON,ZWISHHITSKINMOTOR,ZHOLIDAYHEADPONYDETAIL,"
1558 "ZWOODPOETRYCOBBLERBENCH,ZAIRFORGIVEHEADFROG,ZBROWBALANCEKEYCHOWDER,"
1559 "ZDISHKEEPBLESTMONITOR,ZCLAMBITARUGULAFAJITA,ZPLIERSPRINTASKOREGANO,"
1560 "ZRADIANTWHENTRYCARD,ZDELAYOUTCOMEHORNAGENCY,ZPURECAKEVIVIDNEATLY,"
1561 "ZPATTERNCLORINEGRANDCOLBY,ZHANDYREPAIRPROTONAIRPORT,ZAGEREEDFROGBASKET,"
1562 "ZSORTMISTYQUOTECABBAGE,ZFOOTTAPWORDENTRY,ZRESOLVEWRISTWRAPAPPLE,"
1563 "ZDILLASKHOKILEMON,ZFILLSTOPLAWJOYFUL,ZACTIONRANGEELEGANTNEUTRON,"
1564 "ZRESORTYARDGREENLET,ZCREAMEVENINGLIPBRANCH,ZWHALEMATHAVOCADOCOPPER,"
1565 "ZGRAYSURVEYWIRELOVE,ZBELLYCRASHITEMLACK,ZHANGERLITHIUMDINNERMEET,"
1566 "ZCARRYFLOORMINNOWDRAGON,ZMALLEQUIPTHANKSGLUE,ZTERMFITTINGHOUSINGCOMMAND,"
1567 "ZONERELEASEAVERAGENURSE,ZLACEADDRESSGROUNDCAREFUL"
1568 " FROM ZLOOKSLIKECOREDATA WHERE ZPK=?1;"
1571 x1
= speedtest1_random()%nRow
;
1572 sqlite3_bind_int(g
.pStmt
, 1, x1
);
1575 speedtest1_end_test();
1579 ** A testset used for debugging speedtest1 itself.
1581 void testset_debug1(void){
1584 char zNum
[2000]; /* A number name */
1587 for(i
=1; i
<=n
; i
++){
1589 x2
= swizzle(x1
, n
);
1590 speedtest1_numbername(x1
, zNum
, sizeof(zNum
));
1591 printf("%5d %5d %5d %s\n", i
, x1
, x2
, zNum
);
1596 #include <sys/types.h>
1600 ** Attempt to display I/O stats on Linux using /proc/PID/io
1602 static void displayLinuxIoStats(FILE *out
){
1605 sqlite3_snprintf(sizeof(z
), z
, "/proc/%d/io", getpid());
1606 in
= fopen(z
, "rb");
1608 while( fgets(z
, sizeof(z
), in
)!=0 ){
1609 static const struct {
1610 const char *zPattern
;
1613 { "rchar: ", "Bytes received by read():" },
1614 { "wchar: ", "Bytes sent to write():" },
1615 { "syscr: ", "Read() system calls:" },
1616 { "syscw: ", "Write() system calls:" },
1617 { "read_bytes: ", "Bytes rcvd from storage:" },
1618 { "write_bytes: ", "Bytes sent to storage:" },
1619 { "cancelled_write_bytes: ", "Cancelled write bytes:" },
1622 for(i
=0; i
<sizeof(aTrans
)/sizeof(aTrans
[0]); i
++){
1623 int n
= (int)strlen(aTrans
[i
].zPattern
);
1624 if( strncmp(aTrans
[i
].zPattern
, z
, n
)==0 ){
1625 fprintf(out
, "-- %-28s %s", aTrans
[i
].zDesc
, &z
[n
]);
1634 #if SQLITE_VERSION_NUMBER<3006018
1635 # define sqlite3_sourceid(X) "(before 3.6.18)"
1638 static int xCompileOptions(void *pCtx
, int nVal
, char **azVal
, char **azCol
){
1639 printf("-- Compile option: %s\n", azVal
[0]);
1643 int main(int argc
, char **argv
){
1644 int doAutovac
= 0; /* True for --autovacuum */
1645 int cacheSize
= 0; /* Desired cache size. 0 means default */
1646 int doExclusive
= 0; /* True for --exclusive */
1647 int nHeap
= 0, mnHeap
= 0; /* Heap size from --heap */
1648 int doIncrvac
= 0; /* True for --incrvacuum */
1649 const char *zJMode
= 0; /* Journal mode */
1650 const char *zKey
= 0; /* Encryption key */
1651 int nLook
= -1, szLook
= 0; /* --lookaside configuration */
1652 int noSync
= 0; /* True for --nosync */
1653 int pageSize
= 0; /* Desired page size. 0 means default */
1654 int nPCache
= 0, szPCache
= 0;/* --pcache configuration */
1655 int doPCache
= 0; /* True if --pcache is seen */
1656 int showStats
= 0; /* True for --stats */
1657 int nThread
= 0; /* --threads value */
1658 int mmapSize
= 0; /* How big of a memory map to use */
1659 const char *zTSet
= "main"; /* Which --testset torun */
1660 int doTrace
= 0; /* True for --trace */
1661 const char *zEncoding
= 0; /* --utf16be or --utf16le */
1662 const char *zDbName
= 0; /* Name of the test database */
1664 void *pHeap
= 0; /* Allocated heap space */
1665 void *pLook
= 0; /* Allocated lookaside space */
1666 void *pPCache
= 0; /* Allocated storage for pcache */
1667 int iCur
, iHi
; /* Stats values, current and "highwater" */
1668 int i
; /* Loop counter */
1669 int rc
; /* API return code */
1671 /* Display the version of SQLite being tested */
1672 printf("-- Speedtest1 for SQLite %s %.50s\n",
1673 sqlite3_libversion(), sqlite3_sourceid());
1675 /* Process command-line arguments */
1681 for(i
=1; i
<argc
; i
++){
1682 const char *z
= argv
[i
];
1684 do{ z
++; }while( z
[0]=='-' );
1685 if( strcmp(z
,"autovacuum")==0 ){
1687 }else if( strcmp(z
,"cachesize")==0 ){
1688 if( i
>=argc
-1 ) fatal_error("missing argument on %s\n", argv
[i
]);
1690 cacheSize
= integerValue(argv
[i
]);
1691 }else if( strcmp(z
,"exclusive")==0 ){
1693 }else if( strcmp(z
,"explain")==0 ){
1696 }else if( strcmp(z
,"heap")==0 ){
1697 if( i
>=argc
-2 ) fatal_error("missing arguments on %s\n", argv
[i
]);
1698 nHeap
= integerValue(argv
[i
+1]);
1699 mnHeap
= integerValue(argv
[i
+2]);
1701 }else if( strcmp(z
,"incrvacuum")==0 ){
1703 }else if( strcmp(z
,"journal")==0 ){
1704 if( i
>=argc
-1 ) fatal_error("missing argument on %s\n", argv
[i
]);
1706 }else if( strcmp(z
,"key")==0 ){
1707 if( i
>=argc
-1 ) fatal_error("missing argument on %s\n", argv
[i
]);
1709 }else if( strcmp(z
,"lookaside")==0 ){
1710 if( i
>=argc
-2 ) fatal_error("missing arguments on %s\n", argv
[i
]);
1711 nLook
= integerValue(argv
[i
+1]);
1712 szLook
= integerValue(argv
[i
+2]);
1714 #if SQLITE_VERSION_NUMBER>=3006000
1715 }else if( strcmp(z
,"multithread")==0 ){
1716 sqlite3_config(SQLITE_CONFIG_MULTITHREAD
);
1717 }else if( strcmp(z
,"nomemstat")==0 ){
1718 sqlite3_config(SQLITE_CONFIG_MEMSTATUS
, 0);
1720 #if SQLITE_VERSION_NUMBER>=3007017
1721 }else if( strcmp(z
, "mmap")==0 ){
1722 if( i
>=argc
-1 ) fatal_error("missing argument on %s\n", argv
[i
]);
1723 mmapSize
= integerValue(argv
[++i
]);
1725 }else if( strcmp(z
,"nosync")==0 ){
1727 }else if( strcmp(z
,"notnull")==0 ){
1729 }else if( strcmp(z
,"pagesize")==0 ){
1730 if( i
>=argc
-1 ) fatal_error("missing argument on %s\n", argv
[i
]);
1731 pageSize
= integerValue(argv
[++i
]);
1732 }else if( strcmp(z
,"pcache")==0 ){
1733 if( i
>=argc
-2 ) fatal_error("missing arguments on %s\n", argv
[i
]);
1734 nPCache
= integerValue(argv
[i
+1]);
1735 szPCache
= integerValue(argv
[i
+2]);
1738 }else if( strcmp(z
,"primarykey")==0 ){
1739 g
.zPK
= "PRIMARY KEY";
1740 }else if( strcmp(z
,"repeat")==0 ){
1741 if( i
>=argc
-1 ) fatal_error("missing arguments on %s\n", argv
[i
]);
1742 g
.nRepeat
= integerValue(argv
[i
+1]);
1744 }else if( strcmp(z
,"reprepare")==0 ){
1746 #if SQLITE_VERSION_NUMBER>=3006000
1747 }else if( strcmp(z
,"serialized")==0 ){
1748 sqlite3_config(SQLITE_CONFIG_SERIALIZED
);
1749 }else if( strcmp(z
,"singlethread")==0 ){
1750 sqlite3_config(SQLITE_CONFIG_SINGLETHREAD
);
1752 }else if( strcmp(z
,"sqlonly")==0 ){
1754 }else if( strcmp(z
,"shrink-memory")==0 ){
1756 }else if( strcmp(z
,"size")==0 ){
1757 if( i
>=argc
-1 ) fatal_error("missing argument on %s\n", argv
[i
]);
1758 g
.szTest
= integerValue(argv
[++i
]);
1759 }else if( strcmp(z
,"stats")==0 ){
1761 }else if( strcmp(z
,"temp")==0 ){
1762 if( i
>=argc
-1 ) fatal_error("missing argument on %s\n", argv
[i
]);
1764 if( argv
[i
][0]<'0' || argv
[i
][0]>'9' || argv
[i
][1]!=0 ){
1765 fatal_error("argument to --temp should be integer between 0 and 9");
1767 g
.eTemp
= argv
[i
][0] - '0';
1768 }else if( strcmp(z
,"testset")==0 ){
1769 if( i
>=argc
-1 ) fatal_error("missing argument on %s\n", argv
[i
]);
1771 }else if( strcmp(z
,"trace")==0 ){
1773 }else if( strcmp(z
,"threads")==0 ){
1774 if( i
>=argc
-1 ) fatal_error("missing argument on %s\n", argv
[i
]);
1775 nThread
= integerValue(argv
[++i
]);
1776 }else if( strcmp(z
,"utf16le")==0 ){
1777 zEncoding
= "utf16le";
1778 }else if( strcmp(z
,"utf16be")==0 ){
1779 zEncoding
= "utf16be";
1780 }else if( strcmp(z
,"verify")==0 ){
1782 }else if( strcmp(z
,"without-rowid")==0 ){
1783 g
.zWR
= "WITHOUT ROWID";
1784 g
.zPK
= "PRIMARY KEY";
1785 }else if( strcmp(z
, "help")==0 || strcmp(z
,"?")==0 ){
1786 printf(zHelp
, argv
[0]);
1789 fatal_error("unknown option: %s\nUse \"%s -?\" for help\n",
1792 }else if( zDbName
==0 ){
1795 fatal_error("surplus argument: %s\nUse \"%s -?\" for help\n",
1799 if( zDbName
!=0 ) unlink(zDbName
);
1800 #if SQLITE_VERSION_NUMBER>=3006001
1802 pHeap
= malloc( nHeap
);
1803 if( pHeap
==0 ) fatal_error("cannot allocate %d-byte heap\n", nHeap
);
1804 rc
= sqlite3_config(SQLITE_CONFIG_HEAP
, pHeap
, nHeap
, mnHeap
);
1805 if( rc
) fatal_error("heap configuration failed: %d\n", rc
);
1808 if( nPCache
>0 && szPCache
>0 ){
1809 pPCache
= malloc( nPCache
*(sqlite3_int64
)szPCache
);
1810 if( pPCache
==0 ) fatal_error("cannot allocate %lld-byte pcache\n",
1811 nPCache
*(sqlite3_int64
)szPCache
);
1813 rc
= sqlite3_config(SQLITE_CONFIG_PAGECACHE
, pPCache
, szPCache
, nPCache
);
1814 if( rc
) fatal_error("pcache configuration failed: %d\n", rc
);
1817 sqlite3_config(SQLITE_CONFIG_LOOKASIDE
, 0, 0);
1821 /* Open the database and the input file */
1822 if( sqlite3_open(zDbName
, &g
.db
) ){
1823 fatal_error("Cannot open database file: %s\n", zDbName
);
1825 #if SQLITE_VERSION_NUMBER>=3006001
1826 if( nLook
>0 && szLook
>0 ){
1827 pLook
= malloc( nLook
*szLook
);
1828 rc
= sqlite3_db_config(g
.db
, SQLITE_DBCONFIG_LOOKASIDE
, pLook
, szLook
,nLook
);
1829 if( rc
) fatal_error("lookaside configuration failed: %d\n", rc
);
1833 /* Set database connection options */
1834 sqlite3_create_function(g
.db
, "random", 0, SQLITE_UTF8
, 0, randomFunc
, 0, 0);
1835 #ifndef SQLITE_OMIT_DEPRECATED
1836 if( doTrace
) sqlite3_trace(g
.db
, traceCallback
, 0);
1839 speedtest1_exec("PRAGMA mmap_size=%d", mmapSize
);
1841 speedtest1_exec("PRAGMA threads=%d", nThread
);
1843 speedtest1_exec("PRAGMA key('%s')", zKey
);
1846 speedtest1_exec("PRAGMA encoding=%s", zEncoding
);
1849 speedtest1_exec("PRAGMA auto_vacuum=FULL");
1850 }else if( doIncrvac
){
1851 speedtest1_exec("PRAGMA auto_vacuum=INCREMENTAL");
1854 speedtest1_exec("PRAGMA page_size=%d", pageSize
);
1857 speedtest1_exec("PRAGMA cache_size=%d", cacheSize
);
1859 if( noSync
) speedtest1_exec("PRAGMA synchronous=OFF");
1861 speedtest1_exec("PRAGMA locking_mode=EXCLUSIVE");
1864 speedtest1_exec("PRAGMA journal_mode=%s", zJMode
);
1867 if( g
.bExplain
) printf(".explain\n.echo on\n");
1868 if( strcmp(zTSet
,"main")==0 ){
1870 }else if( strcmp(zTSet
,"debug1")==0 ){
1872 }else if( strcmp(zTSet
,"orm")==0 ){
1874 }else if( strcmp(zTSet
,"cte")==0 ){
1876 }else if( strcmp(zTSet
,"rtree")==0 ){
1877 #ifdef SQLITE_ENABLE_RTREE
1878 testset_rtree(6, 147);
1880 fatal_error("compile with -DSQLITE_ENABLE_RTREE to enable "
1881 "the R-Tree tests\n");
1884 fatal_error("unknown testset: \"%s\"\nChoices: main debug1 cte rtree\n",
1890 sqlite3_exec(g
.db
, "PRAGMA compile_options", xCompileOptions
, 0, 0);
1893 /* Database connection statistics printed after both prepared statements
1894 ** have been finalized */
1895 #if SQLITE_VERSION_NUMBER>=3007009
1897 sqlite3_db_status(g
.db
, SQLITE_DBSTATUS_LOOKASIDE_USED
, &iCur
, &iHi
, 0);
1898 printf("-- Lookaside Slots Used: %d (max %d)\n", iCur
,iHi
);
1899 sqlite3_db_status(g
.db
, SQLITE_DBSTATUS_LOOKASIDE_HIT
, &iCur
, &iHi
, 0);
1900 printf("-- Successful lookasides: %d\n", iHi
);
1901 sqlite3_db_status(g
.db
, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE
, &iCur
,&iHi
,0);
1902 printf("-- Lookaside size faults: %d\n", iHi
);
1903 sqlite3_db_status(g
.db
, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL
, &iCur
,&iHi
,0);
1904 printf("-- Lookaside OOM faults: %d\n", iHi
);
1905 sqlite3_db_status(g
.db
, SQLITE_DBSTATUS_CACHE_USED
, &iCur
, &iHi
, 0);
1906 printf("-- Pager Heap Usage: %d bytes\n", iCur
);
1907 sqlite3_db_status(g
.db
, SQLITE_DBSTATUS_CACHE_HIT
, &iCur
, &iHi
, 1);
1908 printf("-- Page cache hits: %d\n", iCur
);
1909 sqlite3_db_status(g
.db
, SQLITE_DBSTATUS_CACHE_MISS
, &iCur
, &iHi
, 1);
1910 printf("-- Page cache misses: %d\n", iCur
);
1911 #if SQLITE_VERSION_NUMBER>=3007012
1912 sqlite3_db_status(g
.db
, SQLITE_DBSTATUS_CACHE_WRITE
, &iCur
, &iHi
, 1);
1913 printf("-- Page cache writes: %d\n", iCur
);
1915 sqlite3_db_status(g
.db
, SQLITE_DBSTATUS_SCHEMA_USED
, &iCur
, &iHi
, 0);
1916 printf("-- Schema Heap Usage: %d bytes\n", iCur
);
1917 sqlite3_db_status(g
.db
, SQLITE_DBSTATUS_STMT_USED
, &iCur
, &iHi
, 0);
1918 printf("-- Statement Heap Usage: %d bytes\n", iCur
);
1922 sqlite3_close(g
.db
);
1924 #if SQLITE_VERSION_NUMBER>=3006001
1925 /* Global memory usage statistics printed after the database connection
1926 ** has closed. Memory usage should be zero at this point. */
1928 sqlite3_status(SQLITE_STATUS_MEMORY_USED
, &iCur
, &iHi
, 0);
1929 printf("-- Memory Used (bytes): %d (max %d)\n", iCur
,iHi
);
1930 #if SQLITE_VERSION_NUMBER>=3007000
1931 sqlite3_status(SQLITE_STATUS_MALLOC_COUNT
, &iCur
, &iHi
, 0);
1932 printf("-- Outstanding Allocations: %d (max %d)\n", iCur
,iHi
);
1934 sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW
, &iCur
, &iHi
, 0);
1935 printf("-- Pcache Overflow Bytes: %d (max %d)\n", iCur
,iHi
);
1936 sqlite3_status(SQLITE_STATUS_MALLOC_SIZE
, &iCur
, &iHi
, 0);
1937 printf("-- Largest Allocation: %d bytes\n",iHi
);
1938 sqlite3_status(SQLITE_STATUS_PAGECACHE_SIZE
, &iCur
, &iHi
, 0);
1939 printf("-- Largest Pcache Allocation: %d bytes\n",iHi
);
1945 displayLinuxIoStats(stdout
);
1949 /* Release memory */