]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix up the floating-point speed tests so that they only need to be run once
authordrh <>
Fri, 27 Mar 2026 20:18:06 +0000 (20:18 +0000)
committerdrh <>
Fri, 27 Mar 2026 20:18:06 +0000 (20:18 +0000)
to get a performance comparision.  Provide the fp-speed-test makefile target
to build and run them both.

FossilOrigin-Name: 09e0e78a8265c2e2bc36fef1fa88bd5bf414f9b776966c1c91a4ed4b7866331d

Makefile.msc
main.mk
manifest
manifest.uuid
test/fp-speed-1.c
test/fp-speed-2.c

index 6f954fb922fd258e66d6d258233dbccff4115e19..76b9ddfc3bbbe546ecb1c95c11c378afa845d39c 100644 (file)
@@ -2627,6 +2627,12 @@ smoketest:       $(TESTPROGS)
        @set PATH=$(LIBTCLPATH);$(PATH)
        .\testfixture.exe $(TOP)\test\main.test $(TESTOPTS)
 
+# Measure the performance of floating-point conversions.
+#
+fp-speed-test: fp-speed-1.exe fp-speed-2.exe
+       fp-speed-1 10000000
+       fp-speed-2 10000000
+
 shelltest:
        $(TCLSH_CMD) $(TOP)\test\testrunner.tcl release shell
 
@@ -2719,6 +2725,14 @@ speedtest1.exe:  $(TOP)\test\speedtest1.c $(SQLITE3C) $(SQLITE3H)
        $(LTLINK) $(NO_WARN) $(ST_COMPILE_OPTS) -DSQLITE_OMIT_LOAD_EXTENSION \
                $(TOP)\test\speedtest1.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
 
+fp-speed-1.exe:        $(TOP)\test\fp-speed-1.c $(SQLITE3C) $(SQLITE3H)
+       $(LTLINK) $(NO_WARN) $(ST_COMPILE_OPTS) -DSQLITE_OMIT_LOAD_EXTENSION \
+               $(TOP)\test\fp-speed-1.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
+
+fp-speed-2.exe:        $(TOP)\test\fp-speed-2.c $(SQLITE3C) $(SQLITE3H)
+       $(LTLINK) $(NO_WARN) $(ST_COMPILE_OPTS) -DSQLITE_OMIT_LOAD_EXTENSION \
+               $(TOP)\test\fp-speed-2.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
+
 kvtest.exe:    $(TOP)\test\kvtest.c $(SQLITE3C) $(SQLITE3H)
        $(LTLINK) $(NO_WARN) $(KV_COMPILE_OPTS) \
                $(TOP)\test\kvtest.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
@@ -2908,6 +2922,7 @@ clean:
        del /Q LogEst.exe fts3view.exe rollback-test.exe showdb.exe dbdump.exe 2>NUL
        del /Q changeset.exe 2>NUL
        del /Q showjournal.exe showstat4.exe showwal.exe speedtest1.exe 2>NUL
+       del /Q fp-speed-1.exe fp-speed-2.exe 2>NUL
        del /Q mptester.exe wordcount.exe rbu.exe srcck1.exe 2>NUL
        del /Q sqlite3.c sqlite3-*.c sqlite3.h 2>NUL
        del /Q sqlite3rc.h 2>NUL
diff --git a/main.mk b/main.mk
index 037634091a95280c8f0eef3746480e2ad6899fec..fa6d35c8ae9d52f2662dac7d64b007899f31ceab 100644 (file)
--- a/main.mk
+++ b/main.mk
@@ -1920,6 +1920,12 @@ smoketest:       $(TESTPROGS) fuzzcheck$(T.exe)
 shelltest:
        $(TCLSH_CMD) $(TOP)/test/testrunner.tcl release shell
 
+# Test performance of floating-point conversions.
+#
+fp-speed-test: fp-speed-1$(T.exe) fp-speed-2$(T.exe)
+       ./fp-speed-1 10000000
+       ./fp-speed-2 10000000
+
 #
 # sqlite3_analyzer.c build depends on $(LINK_TOOLS_DYNAMICALLY).
 #
@@ -2037,6 +2043,14 @@ speedtest1$(T.exe):      $(TOP)/test/speedtest1.c sqlite3.c Makefile
                $(LDFLAGS.libsqlite3)
 xbin: speedtest1$(T.exe)
 
+fp-speed-1$(T.exe):    $(TOP)/test/fp-speed-1.c sqlite3.o Makefile
+       $(T.link) $(ST_OPT) -o $@ $(TOP)/test/fp-speed-1.c sqlite3.o \
+               $(LDFLAGS.libsqlite3)
+
+fp-speed-2$(T.exe):    $(TOP)/test/fp-speed-2.c sqlite3.o Makefile
+       $(T.link) $(ST_OPT) -o $@ $(TOP)/test/fp-speed-2.c sqlite3.o \
+               $(LDFLAGS.libsqlite3)
+
 startup$(T.exe):       $(TOP)/test/startup.c sqlite3.c
        $(T.link) -Os -g -USQLITE_THREADSAFE -DSQLITE_THREADSAFE=0 \
                -o $@ $(TOP)/test/startup.c sqlite3.c $(LDFLAGS.libsqlite3)
@@ -2482,6 +2496,7 @@ tidy:
        rm -f tclsqlite3$(T.exe) $(TESTPROGS)
        rm -f LogEst$(T.exe) fts3view$(T.exe) rollback-test$(T.exe) showdb$(T.exe)
        rm -f showjournal$(T.exe) showstat4$(T.exe) showwal$(T.exe) speedtest1$(T.exe)
+       rm -f fp-speed-1$(T.exe) fp-speed-2$(T.exe)
        rm -f wordcount$(T.exe) changeset$(T.exe) version-info$(T.exe)
        rm -f *.exp *.vsix pkgIndex.tcl
        rm -f sqlite3_analyzer$(T.exe) sqlite3_rsync$(T.exe) sqlite3_expert$(T.exe)
index 321ffe33405bf1928b5d9848e292fc872dd4b98d..47c7973f520b6fe587dcfbc3bd80feef23881b9a 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,12 +1,12 @@
-C Add\sa\scomment\sto\stest/fptest01.sql\sto\sremind\sus\sthat\sfailures\sin\sthat\nscript\smight\snot\sbe\sthe\sfault\sof\sSQLite.
-D 2026-03-27T19:25:25.815
+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.
+D 2026-03-27T20:18:06.002
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md 6bc480fc673fb4acbc4094e77edb326267dd460162d7723c7f30bee2d3d9e97d
 F Makefile.in 3ce07126d7e87c7464301482e161fdae6a51d0a2aa06b200b8f0000ef4d6163b
 F Makefile.linux-generic bd3e3cacd369821a6241d4ea1967395c962dfe3057e38cb0a435cee0e8b789d0
-F Makefile.msc bee487191dcc9394d0e38854aa311b79d4488e0b877cc1a1a61ba5ad8ef225a6
+F Makefile.msc 05dffae7914a3e3accd6056d71ec2bf5dff563a728592373b828882a52141067
 F README.md 3fa51fc7ababc32edd175ae8b2986c86d5ea120c1cb1e57c7f7849492d1405ec
 F VERSION 31435e19ded2aae3c1c67dacf06a995a37fd1b253baec5899b78d64cd29db4f7
 F art/icon-243x273.gif 9750b734f82fdb3dc43127753d5e6fbf3b62c9f4e136c2fbf573b2f57ea87af5
@@ -655,7 +655,7 @@ F ext/wasm/tests/opfs/sahpool/index.html be736567fd92d3ecb9754c145755037cbbd2bca
 F ext/wasm/tests/opfs/sahpool/sahpool-pausing.js f264925cfc82155de38cecb3d204c36e0f6991460fff0cb7c15079454679a4e2
 F ext/wasm/tests/opfs/sahpool/sahpool-worker.js bd25a43fc2ab2d1bafd8f2854ad3943ef673f7c3be03e95ecf1612ff6e8e2a61
 F magic.txt 5ade0bc977aa135e79e3faaea894d5671b26107cc91e70783aa7dc83f22f3ba0
-F main.mk 64479b612d66a3f1a3ab498a3a40607937f614168987d8cda8320fa8be517fac
+F main.mk ac1cafc6f08d108f99cf74f686f1a7f8a08569279341f9d6ffb7745c1fba66f6
 F make.bat a136fd0b1c93e89854a86d5f4edcf0386d211e5d5ec2434480f6eea436c7420c
 F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271
 F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504
@@ -1126,8 +1126,8 @@ F test/fkey_malloc.test 594a7ea1fbab553c036c70813cd8bd9407d63749
 F test/fordelete.test ba98f14446b310f9c9d935b97ec748753d0144a28b356ba30d1f4f6958fdde5c
 F test/fork-test.c 9ac2e6423a1d38df3d6be0e8ac15608b545de21e2b19d9d876254c5931b63edb
 F test/format4.test eeae341953db8b6bda7f549044797c3278a6cc345d11ada81471671b654f8ef4
-F test/fp-speed-1.c 34216fbd0a98613f20cfaf234d8206afdff5312c2bd266f588e1cd40c5f25c3e
-F test/fp-speed-2.c af6b1fbd368c3981566b14e3c1932badf31c65624456e10dd36433ef3be6b8fb
+F test/fp-speed-1.c 0e2c6d117ba08979392db480042d44a2ebb16447f831676b5388911b357134a7
+F test/fp-speed-2.c 26638811adc2f98618569bb90b2ed1c409c36ba79b543e6961d923d2a177931c
 F test/fpconv1.test 63f352682fa65601a326563ad633086df6ab194e6ed5e7366786f38a525a7fd7
 F test/fptest01.sql 3d84f10bb1cc220b59207354c887d720289903adeb9972a29d6bfcb3fec0df95
 F test/fts-9fd058691.test 78b887e30ae6816df0e1fed6259de4b5a64ad33c
@@ -2196,8 +2196,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee
 F tool/warnings.sh a554d13f6e5cf3760f041b87939e3d616ec6961859c3245e8ef701d1eafc2ca2
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
 F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c
-P bbf2d648376a965605d5c641a889ab7ef365bc53788d984c054468e9889deee6
-R 971109cd33785e0666135a8a29743846
+P 65efcb0a2ed49fa2fd747b5f034d976ed3cb4a01a185bcada70bf8a5208f3841
+R 9241b33114a318ec370d37f5c35f3684
 U drh
-Z 5fc5b64177dcf49d75363f6b7491a851
+Z c5759a178764214d2ef838560a990f1c
 # Remove this line to create a well-formed Fossil manifest.
index f9a9020fb5674984f5e0cc95ef8ade0f09e0908a..83d46de22c1d1b88669fc72bdf75c49bd286b2bf 100644 (file)
@@ -1 +1 @@
-65efcb0a2ed49fa2fd747b5f034d976ed3cb4a01a185bcada70bf8a5208f3841
+09e0e78a8265c2e2bc36fef1fa88bd5bf414f9b776966c1c91a4ed4b7866331d
index a9831406c882be8e36a48cd3572886050398cae9..bd78f2cb45b099a97089a0c29faa9503871d9ba3 100644 (file)
@@ -13,8 +13,7 @@
 **
 ** To run the test:
 **
-**    ./a.out 0 10000000     <-- standard library
-**    ./a.out 1 10000000     <-- SQLite
+**    ./a.out 10000000
 */
 #include "sqlite3.h"
 #include <stdio.h>
@@ -165,35 +164,42 @@ static sqlite3_int64 timeOfDay(void){
 int main(int argc, char **argv){
   int i;
   int cnt;
-  int fg;
-  sqlite3_int64 tm;
+  static const char *zFmt = "%.17g";
+  sqlite3_int64 tm1, tm2;
   char zBuf[1000];
 
-  if( argc!=3 ){
-    fprintf(stderr, "Usage:  %s FLAG COUNT\n", argv[0]);
+  if( argc!=2 ){
+    printf("Usage:  %s COUNT\n", argv[0]);
+    printf("Suggested value for COUNT is 10 million\n");
+    return 1;
+  }
+  cnt = atoi(argv[1]);
+  if( cnt<100 ){
+    printf("Minimum COUNT value is 100");
     return 1;
   }
-  cnt = atoi(argv[2]);
-  fg = atoi(argv[1]);
 
-  tm = timeOfDay();
-  switch( fg % 3 ){
-    case 0: {
-      printf("Doing %d calls to C-lib sprintf()\n", cnt);
-      for(i=0; i<cnt; i++){
-        sprintf(zBuf, "%.17g", aVal[i%NN]);
-      }
-      break;
-    }
-    case 1: {
-      printf("Doing %d calls to sqlite3_snprintf()\n", cnt);
-      for(i=0; i<cnt; i++){
-        sqlite3_snprintf(sizeof(zBuf), zBuf, "%.17g", aVal[i%NN]);
-      }
-      break;
-    }
+  tm1 = timeOfDay();
+  printf("C-library sprintf(\"%s\"): ", zFmt);
+  fflush(stdout);
+  for(i=0; i<cnt; i++){
+    sprintf(zBuf, zFmt, aVal[i%NN]);
+  }
+  tm1 = timeOfDay() - tm1;
+  printf("%6.1f ns/call, %9.6f sec total\n", tm1*1.0e+3/(double)cnt,tm1*1.0e-6);
+  tm2 = timeOfDay();
+  printf("sqlite3_snprintf(\"%s\"):  ", zFmt);
+  for(i=0; i<cnt; i++){
+    sqlite3_snprintf(sizeof(zBuf), zBuf, zFmt, aVal[i%NN]);
+  }
+  tm2 = timeOfDay() - tm2;
+  printf("%6.1f ns/call, %9.6f sec total\n", tm2*1.0e+3/(double)cnt,tm2*1.0e-6);
+  if( tm1 < tm2 ){
+    printf("sprintf() is about %g times faster than sqlite3_snprintf()\n",
+           (double)tm2/(double)tm1);
+  }else{
+    printf("sqlite3_snprintf() is about %g times faster than sprintf()\n",
+           (double)tm1/(double)tm2);
   }
-  tm = timeOfDay() - tm;
-  printf("Elapse time: %lld.%06lld seconds\n", tm/1000000, tm%1000000);
   return 0;
 }
index e3c8cd7878d9e3f2a0b549218f7d56345617d99b..dc7175ce4fee9e717bc2461da62fb0707bdaf978 100644 (file)
@@ -13,9 +13,7 @@
 **
 ** To run the test:
 **
-**    ./a.out 0 10000000     <-- standard library
-**    ./a.out 1 10000000     <-- SQLite
-**    ./a.out 2 10000000     <-- test program overhead
+**    ./a.out 10000000
 */
 #include "sqlite3.h"
 #include <string.h>
@@ -169,69 +167,84 @@ int main(int argc, char **argv){
   int i;
   int cnt;
   int fg;
-  sqlite3_int64 tm;
+  sqlite3_int64 tm[3];
   double arSum[401];
   char z[1000];
 
-  if( argc!=3 ){
-    fprintf(stderr, "Usage:  %s FLAG COUNT\n", argv[0]);
+  if( argc!=2 ){
+    printf("Usage:  %s COUNT\n", argv[0]);
+    printf("Suggested value for COUNT is 10 million\n");
     return 1;
   }
-  cnt = atoi(argv[2]);
-  fg = atoi(argv[1]);
-
-  tm = timeOfDay();
-  switch( fg % 4 ){
-    case 0: printf("Doing %d calls to C-lib atof()\n", cnt); break;
-    case 1: printf("Doing %d calls to sqlite3AtoF()\n", cnt); break;
-    case 2: printf("Test overhead only for %d cases\n", cnt); break;
-    case 3: printf("Print the first %d cases\n", cnt); break;
+  cnt = atoi(argv[1]);
+  if( cnt<100 ){
+    printf("Minimum COUNT value is 100");
+    return 1;
   }
-  memset(arSum, 0, sizeof(arSum));
-  for(i=0; i<cnt; i++){
-    int e, ex, len, ix;
-    ex = i%401;
-    e = ex - 200;
-    len = (i/401)%16 + 4;
-    ix = (i/(401*16))%NN;
-    memcpy(z, aVal[ix], len);
-    z[len++] = 'e';
-    if( e<0 ){
-      z[len++] = '-';
-      e = -e;
-    }else{
-      z[len++] = '+';
+
+  for(fg=0; fg<=2; fg++){
+    tm[fg] = timeOfDay();
+    switch( fg ){
+      case 0: printf("C-lib atof():  "); break;
+      case 1: printf("sqlite3AtoF(): "); break;
+      case 2: printf("Test overhead: "); break;
     }
-    z[len++] = e/100 + '0';
-    z[len++] = (e/10)%10 + '0';
-    z[len++] = e%10 + '0';
-    z[len] = 0;
-    switch( fg % 4 ){
-      case 0: {
-        arSum[ex] += atof(z);
-        break;
-      }
-      case 1: {
-        double r = 0.0;
-        sqlite3_test_control(SQLITE_TESTCTRL_ATOF, z, &r);
-        arSum[ex] += r;
-        break;
+    fflush(stdout);
+    memset(arSum, 0, sizeof(arSum));
+    for(i=0; i<cnt; i++){
+      int e, ex, len, ix;
+      ex = i%401;
+      e = ex - 200;
+      len = (i/401)%16 + 4;
+      ix = (i/(401*16))%NN;
+      memcpy(z, aVal[ix], len);
+      z[len++] = 'e';
+      if( e<0 ){
+        z[len++] = '-';
+        e = -e;
+      }else{
+        z[len++] = '+';
       }
-      case 2: {
-        double r = (double)i;
-        arSum[ex] += r;
+      z[len++] = e/100 + '0';
+      z[len++] = (e/10)%10 + '0';
+      z[len++] = e%10 + '0';
+      z[len] = 0;
+      switch( fg ){
+        case 0: {
+          arSum[ex] += atof(z);
+          break;
+        }
+        case 1: {
+          double r = 0.0;
+          sqlite3_test_control(SQLITE_TESTCTRL_ATOF, z, &r);
+          arSum[ex] += r;
+          break;
+        }
+        case 2: {
+          double r = (double)i;
+          arSum[ex] += r;
+          break;
+        }
         break;
       }
-      case 3: {
-        printf("%s\n", z);
-        break;
-      }
-      break;
     }
+    for(i=1; i<=400; i++) arSum[0] += arSum[i];
+    tm[fg] = timeOfDay() - tm[fg];
+    printf("%6.1f ns/test, %9.6f sec total", tm[fg]*1e3/cnt, tm[fg]*1e-6);
+    if( fg<2 ){
+      printf(", cksum: %g\n", arSum[0]);
+    }else{
+      printf("\n");
+    }
+  }
+  tm[0] -= tm[2];
+  tm[1] -= tm[2];
+  if( tm[0] < tm[1] ){
+    printf("atof() is about %g times faster than sqlite3AtoF()\n",
+           (double)tm[1]/(double)tm[0]);
+  }else{
+    printf("sqlite3AtoF() is about %g times faster than atof()\n",
+           (double)tm[0]/(double)tm[1]);
   }
-  for(i=1; i<=400; i++) arSum[0] += arSum[i];
-  printf("Checksum: %g\n", arSum[0]);
-  tm = timeOfDay() - tm;
-  printf("Elapse time: %lld.%06lld seconds\n", tm/1000000, tm%1000000);
   return 0;
 }