Skip to content

Commit ff8a089

Browse files
author
drh
committed
Fix up the floating-point speed tests so that they only need to be run once
to get a performance comparision. Provide the fp-speed-test makefile target to build and run them both. FossilOrigin-Name: 09e0e78a8265c2e2bc36fef1fa88bd5bf414f9b776966c1c91a4ed4b7866331d
1 parent a2f78f6 commit ff8a089

6 files changed

Lines changed: 140 additions & 91 deletions

File tree

Makefile.msc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2627,6 +2627,12 @@ smoketest: $(TESTPROGS)
26272627
@set PATH=$(LIBTCLPATH);$(PATH)
26282628
.\testfixture.exe $(TOP)\test\main.test $(TESTOPTS)
26292629

2630+
# Measure the performance of floating-point conversions.
2631+
#
2632+
fp-speed-test: fp-speed-1.exe fp-speed-2.exe
2633+
fp-speed-1 10000000
2634+
fp-speed-2 10000000
2635+
26302636
shelltest:
26312637
$(TCLSH_CMD) $(TOP)\test\testrunner.tcl release shell
26322638

@@ -2719,6 +2725,14 @@ speedtest1.exe: $(TOP)\test\speedtest1.c $(SQLITE3C) $(SQLITE3H)
27192725
$(LTLINK) $(NO_WARN) $(ST_COMPILE_OPTS) -DSQLITE_OMIT_LOAD_EXTENSION \
27202726
$(TOP)\test\speedtest1.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
27212727

2728+
fp-speed-1.exe: $(TOP)\test\fp-speed-1.c $(SQLITE3C) $(SQLITE3H)
2729+
$(LTLINK) $(NO_WARN) $(ST_COMPILE_OPTS) -DSQLITE_OMIT_LOAD_EXTENSION \
2730+
$(TOP)\test\fp-speed-1.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
2731+
2732+
fp-speed-2.exe: $(TOP)\test\fp-speed-2.c $(SQLITE3C) $(SQLITE3H)
2733+
$(LTLINK) $(NO_WARN) $(ST_COMPILE_OPTS) -DSQLITE_OMIT_LOAD_EXTENSION \
2734+
$(TOP)\test\fp-speed-2.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
2735+
27222736
kvtest.exe: $(TOP)\test\kvtest.c $(SQLITE3C) $(SQLITE3H)
27232737
$(LTLINK) $(NO_WARN) $(KV_COMPILE_OPTS) \
27242738
$(TOP)\test\kvtest.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
@@ -2908,6 +2922,7 @@ clean:
29082922
del /Q LogEst.exe fts3view.exe rollback-test.exe showdb.exe dbdump.exe 2>NUL
29092923
del /Q changeset.exe 2>NUL
29102924
del /Q showjournal.exe showstat4.exe showwal.exe speedtest1.exe 2>NUL
2925+
del /Q fp-speed-1.exe fp-speed-2.exe 2>NUL
29112926
del /Q mptester.exe wordcount.exe rbu.exe srcck1.exe 2>NUL
29122927
del /Q sqlite3.c sqlite3-*.c sqlite3.h 2>NUL
29132928
del /Q sqlite3rc.h 2>NUL

main.mk

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,6 +1920,12 @@ smoketest: $(TESTPROGS) fuzzcheck$(T.exe)
19201920
shelltest:
19211921
$(TCLSH_CMD) $(TOP)/test/testrunner.tcl release shell
19221922

1923+
# Test performance of floating-point conversions.
1924+
#
1925+
fp-speed-test: fp-speed-1$(T.exe) fp-speed-2$(T.exe)
1926+
./fp-speed-1 10000000
1927+
./fp-speed-2 10000000
1928+
19231929
#
19241930
# sqlite3_analyzer.c build depends on $(LINK_TOOLS_DYNAMICALLY).
19251931
#
@@ -2037,6 +2043,14 @@ speedtest1$(T.exe): $(TOP)/test/speedtest1.c sqlite3.c Makefile
20372043
$(LDFLAGS.libsqlite3)
20382044
xbin: speedtest1$(T.exe)
20392045

2046+
fp-speed-1$(T.exe): $(TOP)/test/fp-speed-1.c sqlite3.o Makefile
2047+
$(T.link) $(ST_OPT) -o $@ $(TOP)/test/fp-speed-1.c sqlite3.o \
2048+
$(LDFLAGS.libsqlite3)
2049+
2050+
fp-speed-2$(T.exe): $(TOP)/test/fp-speed-2.c sqlite3.o Makefile
2051+
$(T.link) $(ST_OPT) -o $@ $(TOP)/test/fp-speed-2.c sqlite3.o \
2052+
$(LDFLAGS.libsqlite3)
2053+
20402054
startup$(T.exe): $(TOP)/test/startup.c sqlite3.c
20412055
$(T.link) -Os -g -USQLITE_THREADSAFE -DSQLITE_THREADSAFE=0 \
20422056
-o $@ $(TOP)/test/startup.c sqlite3.c $(LDFLAGS.libsqlite3)
@@ -2482,6 +2496,7 @@ tidy:
24822496
rm -f tclsqlite3$(T.exe) $(TESTPROGS)
24832497
rm -f LogEst$(T.exe) fts3view$(T.exe) rollback-test$(T.exe) showdb$(T.exe)
24842498
rm -f showjournal$(T.exe) showstat4$(T.exe) showwal$(T.exe) speedtest1$(T.exe)
2499+
rm -f fp-speed-1$(T.exe) fp-speed-2$(T.exe)
24852500
rm -f wordcount$(T.exe) changeset$(T.exe) version-info$(T.exe)
24862501
rm -f *.exp *.vsix pkgIndex.tcl
24872502
rm -f sqlite3_analyzer$(T.exe) sqlite3_rsync$(T.exe) sqlite3_expert$(T.exe)

manifest

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
C Add\sa\scomment\sto\stest/fptest01.sql\sto\sremind\sus\sthat\sfailures\sin\sthat\nscript\smight\snot\sbe\sthe\sfault\sof\sSQLite.
2-
D 2026-03-27T19:25:25.815
1+
C Fix\sup\sthe\sfloating-point\sspeed\stests\sso\sthat\sthey\sonly\sneed\sto\sbe\srun\sonce\nto\sget\sa\sperformance\scomparision.\s\sProvide\sthe\sfp-speed-test\smakefile\starget\nto\sbuild\sand\srun\sthem\sboth.
2+
D 2026-03-27T20:18:06.002
33
F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
44
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
55
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
66
F LICENSE.md 6bc480fc673fb4acbc4094e77edb326267dd460162d7723c7f30bee2d3d9e97d
77
F Makefile.in 3ce07126d7e87c7464301482e161fdae6a51d0a2aa06b200b8f0000ef4d6163b
88
F Makefile.linux-generic bd3e3cacd369821a6241d4ea1967395c962dfe3057e38cb0a435cee0e8b789d0
9-
F Makefile.msc bee487191dcc9394d0e38854aa311b79d4488e0b877cc1a1a61ba5ad8ef225a6
9+
F Makefile.msc 05dffae7914a3e3accd6056d71ec2bf5dff563a728592373b828882a52141067
1010
F README.md 3fa51fc7ababc32edd175ae8b2986c86d5ea120c1cb1e57c7f7849492d1405ec
1111
F VERSION 31435e19ded2aae3c1c67dacf06a995a37fd1b253baec5899b78d64cd29db4f7
1212
F art/icon-243x273.gif 9750b734f82fdb3dc43127753d5e6fbf3b62c9f4e136c2fbf573b2f57ea87af5
@@ -655,7 +655,7 @@ F ext/wasm/tests/opfs/sahpool/index.html be736567fd92d3ecb9754c145755037cbbd2bca
655655
F ext/wasm/tests/opfs/sahpool/sahpool-pausing.js f264925cfc82155de38cecb3d204c36e0f6991460fff0cb7c15079454679a4e2
656656
F ext/wasm/tests/opfs/sahpool/sahpool-worker.js bd25a43fc2ab2d1bafd8f2854ad3943ef673f7c3be03e95ecf1612ff6e8e2a61
657657
F magic.txt 5ade0bc977aa135e79e3faaea894d5671b26107cc91e70783aa7dc83f22f3ba0
658-
F main.mk 64479b612d66a3f1a3ab498a3a40607937f614168987d8cda8320fa8be517fac
658+
F main.mk ac1cafc6f08d108f99cf74f686f1a7f8a08569279341f9d6ffb7745c1fba66f6
659659
F make.bat a136fd0b1c93e89854a86d5f4edcf0386d211e5d5ec2434480f6eea436c7420c
660660
F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271
661661
F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504
@@ -1126,8 +1126,8 @@ F test/fkey_malloc.test 594a7ea1fbab553c036c70813cd8bd9407d63749
11261126
F test/fordelete.test ba98f14446b310f9c9d935b97ec748753d0144a28b356ba30d1f4f6958fdde5c
11271127
F test/fork-test.c 9ac2e6423a1d38df3d6be0e8ac15608b545de21e2b19d9d876254c5931b63edb
11281128
F test/format4.test eeae341953db8b6bda7f549044797c3278a6cc345d11ada81471671b654f8ef4
1129-
F test/fp-speed-1.c 34216fbd0a98613f20cfaf234d8206afdff5312c2bd266f588e1cd40c5f25c3e
1130-
F test/fp-speed-2.c af6b1fbd368c3981566b14e3c1932badf31c65624456e10dd36433ef3be6b8fb
1129+
F test/fp-speed-1.c 0e2c6d117ba08979392db480042d44a2ebb16447f831676b5388911b357134a7
1130+
F test/fp-speed-2.c 26638811adc2f98618569bb90b2ed1c409c36ba79b543e6961d923d2a177931c
11311131
F test/fpconv1.test 63f352682fa65601a326563ad633086df6ab194e6ed5e7366786f38a525a7fd7
11321132
F test/fptest01.sql 3d84f10bb1cc220b59207354c887d720289903adeb9972a29d6bfcb3fec0df95
11331133
F test/fts-9fd058691.test 78b887e30ae6816df0e1fed6259de4b5a64ad33c
@@ -2196,8 +2196,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee
21962196
F tool/warnings.sh a554d13f6e5cf3760f041b87939e3d616ec6961859c3245e8ef701d1eafc2ca2
21972197
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
21982198
F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c
2199-
P bbf2d648376a965605d5c641a889ab7ef365bc53788d984c054468e9889deee6
2200-
R 971109cd33785e0666135a8a29743846
2199+
P 65efcb0a2ed49fa2fd747b5f034d976ed3cb4a01a185bcada70bf8a5208f3841
2200+
R 9241b33114a318ec370d37f5c35f3684
22012201
U drh
2202-
Z 5fc5b64177dcf49d75363f6b7491a851
2202+
Z c5759a178764214d2ef838560a990f1c
22032203
# Remove this line to create a well-formed Fossil manifest.

manifest.uuid

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
65efcb0a2ed49fa2fd747b5f034d976ed3cb4a01a185bcada70bf8a5208f3841
1+
09e0e78a8265c2e2bc36fef1fa88bd5bf414f9b776966c1c91a4ed4b7866331d

test/fp-speed-1.c

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
**
1414
** To run the test:
1515
**
16-
** ./a.out 0 10000000 <-- standard library
17-
** ./a.out 1 10000000 <-- SQLite
16+
** ./a.out 10000000
1817
*/
1918
#include "sqlite3.h"
2019
#include <stdio.h>
@@ -165,35 +164,42 @@ static sqlite3_int64 timeOfDay(void){
165164
int main(int argc, char **argv){
166165
int i;
167166
int cnt;
168-
int fg;
169-
sqlite3_int64 tm;
167+
static const char *zFmt = "%.17g";
168+
sqlite3_int64 tm1, tm2;
170169
char zBuf[1000];
171170

172-
if( argc!=3 ){
173-
fprintf(stderr, "Usage: %s FLAG COUNT\n", argv[0]);
171+
if( argc!=2 ){
172+
printf("Usage: %s COUNT\n", argv[0]);
173+
printf("Suggested value for COUNT is 10 million\n");
174+
return 1;
175+
}
176+
cnt = atoi(argv[1]);
177+
if( cnt<100 ){
178+
printf("Minimum COUNT value is 100");
174179
return 1;
175180
}
176-
cnt = atoi(argv[2]);
177-
fg = atoi(argv[1]);
178181

179-
tm = timeOfDay();
180-
switch( fg % 3 ){
181-
case 0: {
182-
printf("Doing %d calls to C-lib sprintf()\n", cnt);
183-
for(i=0; i<cnt; i++){
184-
sprintf(zBuf, "%.17g", aVal[i%NN]);
185-
}
186-
break;
187-
}
188-
case 1: {
189-
printf("Doing %d calls to sqlite3_snprintf()\n", cnt);
190-
for(i=0; i<cnt; i++){
191-
sqlite3_snprintf(sizeof(zBuf), zBuf, "%.17g", aVal[i%NN]);
192-
}
193-
break;
194-
}
182+
tm1 = timeOfDay();
183+
printf("C-library sprintf(\"%s\"): ", zFmt);
184+
fflush(stdout);
185+
for(i=0; i<cnt; i++){
186+
sprintf(zBuf, zFmt, aVal[i%NN]);
187+
}
188+
tm1 = timeOfDay() - tm1;
189+
printf("%6.1f ns/call, %9.6f sec total\n", tm1*1.0e+3/(double)cnt,tm1*1.0e-6);
190+
tm2 = timeOfDay();
191+
printf("sqlite3_snprintf(\"%s\"): ", zFmt);
192+
for(i=0; i<cnt; i++){
193+
sqlite3_snprintf(sizeof(zBuf), zBuf, zFmt, aVal[i%NN]);
194+
}
195+
tm2 = timeOfDay() - tm2;
196+
printf("%6.1f ns/call, %9.6f sec total\n", tm2*1.0e+3/(double)cnt,tm2*1.0e-6);
197+
if( tm1 < tm2 ){
198+
printf("sprintf() is about %g times faster than sqlite3_snprintf()\n",
199+
(double)tm2/(double)tm1);
200+
}else{
201+
printf("sqlite3_snprintf() is about %g times faster than sprintf()\n",
202+
(double)tm1/(double)tm2);
195203
}
196-
tm = timeOfDay() - tm;
197-
printf("Elapse time: %lld.%06lld seconds\n", tm/1000000, tm%1000000);
198204
return 0;
199205
}

test/fp-speed-2.c

Lines changed: 68 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
**
1414
** To run the test:
1515
**
16-
** ./a.out 0 10000000 <-- standard library
17-
** ./a.out 1 10000000 <-- SQLite
18-
** ./a.out 2 10000000 <-- test program overhead
16+
** ./a.out 10000000
1917
*/
2018
#include "sqlite3.h"
2119
#include <string.h>
@@ -169,69 +167,84 @@ int main(int argc, char **argv){
169167
int i;
170168
int cnt;
171169
int fg;
172-
sqlite3_int64 tm;
170+
sqlite3_int64 tm[3];
173171
double arSum[401];
174172
char z[1000];
175173

176-
if( argc!=3 ){
177-
fprintf(stderr, "Usage: %s FLAG COUNT\n", argv[0]);
174+
if( argc!=2 ){
175+
printf("Usage: %s COUNT\n", argv[0]);
176+
printf("Suggested value for COUNT is 10 million\n");
178177
return 1;
179178
}
180-
cnt = atoi(argv[2]);
181-
fg = atoi(argv[1]);
182-
183-
tm = timeOfDay();
184-
switch( fg % 4 ){
185-
case 0: printf("Doing %d calls to C-lib atof()\n", cnt); break;
186-
case 1: printf("Doing %d calls to sqlite3AtoF()\n", cnt); break;
187-
case 2: printf("Test overhead only for %d cases\n", cnt); break;
188-
case 3: printf("Print the first %d cases\n", cnt); break;
179+
cnt = atoi(argv[1]);
180+
if( cnt<100 ){
181+
printf("Minimum COUNT value is 100");
182+
return 1;
189183
}
190-
memset(arSum, 0, sizeof(arSum));
191-
for(i=0; i<cnt; i++){
192-
int e, ex, len, ix;
193-
ex = i%401;
194-
e = ex - 200;
195-
len = (i/401)%16 + 4;
196-
ix = (i/(401*16))%NN;
197-
memcpy(z, aVal[ix], len);
198-
z[len++] = 'e';
199-
if( e<0 ){
200-
z[len++] = '-';
201-
e = -e;
202-
}else{
203-
z[len++] = '+';
184+
185+
for(fg=0; fg<=2; fg++){
186+
tm[fg] = timeOfDay();
187+
switch( fg ){
188+
case 0: printf("C-lib atof(): "); break;
189+
case 1: printf("sqlite3AtoF(): "); break;
190+
case 2: printf("Test overhead: "); break;
204191
}
205-
z[len++] = e/100 + '0';
206-
z[len++] = (e/10)%10 + '0';
207-
z[len++] = e%10 + '0';
208-
z[len] = 0;
209-
switch( fg % 4 ){
210-
case 0: {
211-
arSum[ex] += atof(z);
212-
break;
213-
}
214-
case 1: {
215-
double r = 0.0;
216-
sqlite3_test_control(SQLITE_TESTCTRL_ATOF, z, &r);
217-
arSum[ex] += r;
218-
break;
192+
fflush(stdout);
193+
memset(arSum, 0, sizeof(arSum));
194+
for(i=0; i<cnt; i++){
195+
int e, ex, len, ix;
196+
ex = i%401;
197+
e = ex - 200;
198+
len = (i/401)%16 + 4;
199+
ix = (i/(401*16))%NN;
200+
memcpy(z, aVal[ix], len);
201+
z[len++] = 'e';
202+
if( e<0 ){
203+
z[len++] = '-';
204+
e = -e;
205+
}else{
206+
z[len++] = '+';
219207
}
220-
case 2: {
221-
double r = (double)i;
222-
arSum[ex] += r;
208+
z[len++] = e/100 + '0';
209+
z[len++] = (e/10)%10 + '0';
210+
z[len++] = e%10 + '0';
211+
z[len] = 0;
212+
switch( fg ){
213+
case 0: {
214+
arSum[ex] += atof(z);
215+
break;
216+
}
217+
case 1: {
218+
double r = 0.0;
219+
sqlite3_test_control(SQLITE_TESTCTRL_ATOF, z, &r);
220+
arSum[ex] += r;
221+
break;
222+
}
223+
case 2: {
224+
double r = (double)i;
225+
arSum[ex] += r;
226+
break;
227+
}
223228
break;
224229
}
225-
case 3: {
226-
printf("%s\n", z);
227-
break;
228-
}
229-
break;
230230
}
231+
for(i=1; i<=400; i++) arSum[0] += arSum[i];
232+
tm[fg] = timeOfDay() - tm[fg];
233+
printf("%6.1f ns/test, %9.6f sec total", tm[fg]*1e3/cnt, tm[fg]*1e-6);
234+
if( fg<2 ){
235+
printf(", cksum: %g\n", arSum[0]);
236+
}else{
237+
printf("\n");
238+
}
239+
}
240+
tm[0] -= tm[2];
241+
tm[1] -= tm[2];
242+
if( tm[0] < tm[1] ){
243+
printf("atof() is about %g times faster than sqlite3AtoF()\n",
244+
(double)tm[1]/(double)tm[0]);
245+
}else{
246+
printf("sqlite3AtoF() is about %g times faster than atof()\n",
247+
(double)tm[0]/(double)tm[1]);
231248
}
232-
for(i=1; i<=400; i++) arSum[0] += arSum[i];
233-
printf("Checksum: %g\n", arSum[0]);
234-
tm = timeOfDay() - tm;
235-
printf("Elapse time: %lld.%06lld seconds\n", tm/1000000, tm%1000000);
236249
return 0;
237250
}

0 commit comments

Comments
 (0)