Fix a case where a corrupt stat4 record could go unrecognized due to integer overflow.
[sqlite.git] / test / fp-speed-1.c
blob5eeb95d348ee7fd6cca72fc2d98b6582e74f0ba1
1 /*
2 ** Performance testing of floating-point binary-to-decimal conversion for
3 ** SQLite versus the standard library.
4 **
5 ** To compile:
6 **
7 ** make sqlite3.c
8 ** gcc -Os -c sqlite3.c
9 ** gcc -I. -Os test/fp-speed-1.c sqlite3.o -ldl -lm -lpthread
11 ** To run the test:
13 ** time ./a.out 0 10000000 <-- standard library
14 ** time ./a.out 1 10000000 <-- SQLite
15 ** time ./a.out 2 10000000 <-- SQLite with long-double disabled
17 static double aVal[] = {
18 -1.0163830486285643089e+063,
19 +0.0049243807391586981e-019,
20 +7.3818732407343994867e-095,
21 +7.0678595219225717143e+000,
22 +9.2807266319850025655e+120,
23 +5.8871050861933394663e+135,
24 -2.2998023621259662805e-168,
25 -1.5903581924910847482e+181,
26 +2.4313441816844978216e-001,
27 -3.8290987328945399091e-147,
28 +1.8787914062744001349e-009,
29 +0.7270653560487146653e-014,
30 +0.0639577697913183665e+107,
31 +5.2292338879315861930e-103,
32 +6.3747682672872231319e-021,
33 +8.6972339538329106984e-129,
34 -9.5074486051597691937e-026,
35 -8.6480257845368753018e-005,
36 -3.5657595775797470332e+017,
37 -7.8323106179731761351e+161,
38 +7.7813875274120800372e+077,
39 -1.8739718928360196596e-050,
40 +8.6898145915593357218e-051,
41 +6.0566766359877837871e+002,
42 +4.1703379217148160678e+199,
43 +2.1283871288746651560e+150,
44 -6.8395236083891810637e+128,
45 -6.2114299763939529155e-147,
46 -2.0753525742614637350e-149,
47 +5.8727459803944290257e-007,
48 +8.5888991062002101817e+010,
49 +6.8624461031355917632e+026,
50 -3.3053986756670905167e-075,
51 -4.3596843152763444945e-108,
52 +0.0834139520104099673e+098,
53 -8.8581986548904222440e-192,
54 -3.6622095428727698202e+038,
55 -6.6965852297025063260e+005,
56 +1.8204169347406488441e-054,
57 +6.5234508038649000384e-065,
58 +1.5923006018219011453e+083,
59 +1.7362555291656389480e+018,
60 +7.2875431976854785882e+160,
61 +1.2835880105958926748e-146,
62 +8.0516253320320819420e-113,
63 +6.6324633399381145440e-030,
64 -1.7126500070280062058e-149,
65 +1.6995738341583712335e+042,
66 +7.6048766923738663725e-112,
67 +0.6159117235449455043e-004,
68 +5.7544894355415943289e-135,
69 +8.2970228592690581890e-023,
70 -6.5531925360163067447e+020,
71 +5.8321334606187030050e+120,
72 +5.6557166509571891727e+095,
73 +0.3322789708438408704e-114,
74 -7.1210648776698686623e-050,
75 -9.6721262526706343301e+179,
76 -3.4583916571377395084e-106,
77 +4.7896094323214750793e-172,
78 -9.6926028040004137875e-056,
79 +7.0683848275381385483e-198,
80 -5.2970114182162961964e-007,
81 -4.4287021200905393271e-170,
82 +0.0728891155732808799e-189,
83 -9.1855462025879447465e+175,
84 +3.7294126234131007796e+015,
85 +2.6857421882792719241e+003,
86 -4.7070607333624685339e+039,
87 +7.2175820768279334274e+136,
88 -8.3678412534261163481e-115,
89 +2.2174844304241822163e+019,
90 +0.1949824588606861016e+112,
91 -9.7334052955672071912e+151,
92 -9.7793887766936999879e-142,
93 -5.1561164587416931561e+139,
94 -7.5048993577765174789e-022,
95 +7.3556076568687784568e+107,
96 -5.0681628575533599865e-144,
97 +1.5209705642027747811e+165,
98 -7.5989782535048296040e-101,
99 +1.3654137203389775871e-016,
100 -1.6441720554651372066e+087,
101 -4.9042433196141125923e+000,
102 -7.7063611961649130777e+118,
103 +0.1699427460930766201e+174,
104 +8.3374317849572216870e-145,
105 -5.2355330480469580072e+081,
106 -3.8510045942194147919e+141,
107 -6.3513622544326339887e-147,
108 +2.3869303484454428988e+049,
109 +3.8352715871620360268e-165,
110 -3.1263120493136887902e+035,
111 -5.5794797002556490823e+051,
112 -8.8109874479595604379e+142,
113 -4.3727360120203216922e+070,
114 -3.1109951189668539974e+170,
115 -9.4841878031704268232e+011,
116 -3.7398451668304407277e+067,
117 +4.8984042008915959963e-091,
119 #define NN (sizeof(aVal)/sizeof(aVal[0]))
121 #include "sqlite3.h"
122 #include <stdio.h>
123 #include <stdlib.h>
125 int main(int argc, char **argv){
126 int i;
127 int cnt;
128 int fg;
129 char zBuf[1000];
131 if( argc!=3 ){
132 fprintf(stderr, "Usage: %s FLAG COUNT\n", argv[0]);
133 return 1;
135 cnt = atoi(argv[2]);
136 fg = atoi(argv[1]);
138 switch( fg % 3 ){
139 case 0: {
140 printf("Doing %d calls to C-lib sprintf()\n", cnt);
141 for(i=0; i<cnt; i++){
142 sprintf(zBuf, "%.26g", aVal[i%NN]);
144 break;
146 case 1: {
147 printf("Doing %d calls to sqlite3_snprintf()\n", cnt);
148 for(i=0; i<cnt; i++){
149 sqlite3_snprintf(sizeof(zBuf), zBuf, "%!.26g", aVal[i%NN]);
151 break;
153 case 2: {
154 printf("Doing %d calls to sqlite3_snprintf() without long double\n", cnt);
155 sqlite3_test_control(SQLITE_TESTCTRL_USELONGDOUBLE, 0);
156 for(i=0; i<cnt; i++){
157 sqlite3_snprintf(sizeof(zBuf), zBuf, "%!.26g", aVal[i%NN]);
159 break;
163 return 0;