OLD | NEW |
1 /* | 1 /* |
2 ** Performance test for SQLite. | 2 ** Performance test for SQLite. |
3 ** | 3 ** |
4 ** This program reads ASCII text from a file named on the command-line. | 4 ** This program reads ASCII text from a file named on the command-line. |
5 ** It converts each SQL statement into UTF16 and submits it to SQLite | 5 ** It converts each SQL statement into UTF16 and submits it to SQLite |
6 ** for evaluation. A new UTF16 database is created at the beginning of | 6 ** for evaluation. A new UTF16 database is created at the beginning of |
7 ** the program. All statements are timed using the high-resolution timer | 7 ** the program. All statements are timed using the high-resolution timer |
8 ** built into Intel-class processors. | 8 ** built into Intel-class processors. |
9 ** | 9 ** |
10 ** To compile this program, first compile the SQLite library separately | 10 ** To compile this program, first compile the SQLite library separately |
(...skipping 11 matching lines...) Expand all Loading... |
22 ** | 22 ** |
23 ** ./a.out database.db test.sql | 23 ** ./a.out database.db test.sql |
24 */ | 24 */ |
25 #include <stdio.h> | 25 #include <stdio.h> |
26 #include <string.h> | 26 #include <string.h> |
27 #include <stdlib.h> | 27 #include <stdlib.h> |
28 #include <ctype.h> | 28 #include <ctype.h> |
29 #include <unistd.h> | 29 #include <unistd.h> |
30 #include "sqlite3.h" | 30 #include "sqlite3.h" |
31 | 31 |
| 32 #define ISSPACE(X) isspace((unsigned char)(X)) |
| 33 |
32 /* | 34 /* |
33 ** hwtime.h contains inline assembler code for implementing | 35 ** hwtime.h contains inline assembler code for implementing |
34 ** high-performance timing routines. | 36 ** high-performance timing routines. |
35 */ | 37 */ |
36 #include "hwtime.h" | 38 #include "hwtime.h" |
37 | 39 |
38 /* | 40 /* |
39 ** Convert a zero-terminated ASCII string into a zero-terminated | 41 ** Convert a zero-terminated ASCII string into a zero-terminated |
40 ** UTF-16le string. Memory to hold the returned string comes | 42 ** UTF-16le string. Memory to hold the returned string comes |
41 ** from malloc() and should be freed by the caller. | 43 ** from malloc() and should be freed by the caller. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 free(utf16); | 135 free(utf16); |
134 for(i=j=0; j<nSql; j++){ | 136 for(i=j=0; j<nSql; j++){ |
135 if( zSql[j]==';' ){ | 137 if( zSql[j]==';' ){ |
136 int isComplete; | 138 int isComplete; |
137 char c = zSql[j+1]; | 139 char c = zSql[j+1]; |
138 zSql[j+1] = 0; | 140 zSql[j+1] = 0; |
139 isComplete = sqlite3_complete(&zSql[i]); | 141 isComplete = sqlite3_complete(&zSql[i]); |
140 zSql[j+1] = c; | 142 zSql[j+1] = c; |
141 if( isComplete ){ | 143 if( isComplete ){ |
142 zSql[j] = 0; | 144 zSql[j] = 0; |
143 while( i<j && isspace(zSql[i]) ){ i++; } | 145 while( i<j && ISSPACE(zSql[i]) ){ i++; } |
144 if( i<j ){ | 146 if( i<j ){ |
145 nStmt++; | 147 nStmt++; |
146 nByte += j-i; | 148 nByte += j-i; |
147 prepareAndRun(db, &zSql[i]); | 149 prepareAndRun(db, &zSql[i]); |
148 } | 150 } |
149 zSql[j] = ';'; | 151 zSql[j] = ';'; |
150 i = j+1; | 152 i = j+1; |
151 } | 153 } |
152 } | 154 } |
153 } | 155 } |
154 iStart = sqlite3Hwtime(); | 156 iStart = sqlite3Hwtime(); |
155 sqlite3_close(db); | 157 sqlite3_close(db); |
156 iElapse = sqlite3Hwtime() - iStart; | 158 iElapse = sqlite3Hwtime() - iStart; |
157 iSetup += iElapse; | 159 iSetup += iElapse; |
158 printf("sqlite3_close() returns in %llu cycles\n", iElapse); | 160 printf("sqlite3_close() returns in %llu cycles\n", iElapse); |
159 printf("\n"); | 161 printf("\n"); |
160 printf("Statements run: %15d\n", nStmt); | 162 printf("Statements run: %15d\n", nStmt); |
161 printf("Bytes of SQL text: %15d\n", nByte); | 163 printf("Bytes of SQL text: %15d\n", nByte); |
162 printf("Total prepare time: %15llu cycles\n", prepTime); | 164 printf("Total prepare time: %15llu cycles\n", prepTime); |
163 printf("Total run time: %15llu cycles\n", runTime); | 165 printf("Total run time: %15llu cycles\n", runTime); |
164 printf("Total finalize time: %15llu cycles\n", finalizeTime); | 166 printf("Total finalize time: %15llu cycles\n", finalizeTime); |
165 printf("Open/Close time: %15llu cycles\n", iSetup); | 167 printf("Open/Close time: %15llu cycles\n", iSetup); |
166 printf("Total Time: %15llu cycles\n", | 168 printf("Total Time: %15llu cycles\n", |
167 prepTime + runTime + finalizeTime + iSetup); | 169 prepTime + runTime + finalizeTime + iSetup); |
168 return 0; | 170 return 0; |
169 } | 171 } |
OLD | NEW |