]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Enhancements to the fp-speed-N.c programs, suggested by Andreas Kupries.
authordrh <>
Sat, 28 Mar 2026 14:17:53 +0000 (14:17 +0000)
committerdrh <>
Sat, 28 Mar 2026 14:17:53 +0000 (14:17 +0000)
FossilOrigin-Name: 7d81ff4c509d4039ef9e2f1066284ec560131422db0cbffa7e1826d71bb8f8e1

manifest
manifest.uuid
test/fp-speed-1.c
test/fp-speed-2.c

index 35d6dd4b3360587b534703a3baa602ade4f279e0..54ef15722e31c45d001aeb8ae1c5d7f374154700 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Reduce\sthe\scompiled\ssize\sof\sthe\squote()\sSQL\sfunction.
-D 2026-03-28T13:59:34.275
+C Enhancements\sto\sthe\sfp-speed-N.c\sprograms,\ssuggested\sby\sAndreas\sKupries.
+D 2026-03-28T14:17:53.130
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -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 0e2c6d117ba08979392db480042d44a2ebb16447f831676b5388911b357134a7
-F test/fp-speed-2.c 26638811adc2f98618569bb90b2ed1c409c36ba79b543e6961d923d2a177931c
+F test/fp-speed-1.c 34a2fe8dc30d0b24bb3e7c16efca0a30452287da6caff7dde86eef882db155a4
+F test/fp-speed-2.c 8afff93f00ac034a48e49182b971404480a495c7be4b8a4310e2075cbbb801d5
 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 75e8703664ae94244284819d9021877a5fc33a268fb86f3e70de20875a766d80
-R 53c0174f1ec620322f6cab99495c3f2a
+P 9ea980a35628f7d0741ab6c65840ab9dab8abb576c6c60109147336452f9637a
+R c4218918ce643c1d84226f485b2be1d8
 U drh
-Z 4c1395d7057fba4fd91b56b6ca2cdace
+Z 734c45e6bb399241b8bc1b6c0f71f745
 # Remove this line to create a well-formed Fossil manifest.
index 79c488cf3c8d6a9c9f9ad7db25f5fc187bd7306e..c734bb4c1521de7bd20107cee1bd800324f2e7d3 100644 (file)
@@ -1 +1 @@
-9ea980a35628f7d0741ab6c65840ab9dab8abb576c6c60109147336452f9637a
+7d81ff4c509d4039ef9e2f1066284ec560131422db0cbffa7e1826d71bb8f8e1
index bd78f2cb45b099a97089a0c29faa9503871d9ba3..c55e723cc0b0eed9182c11ca6a71d8436196494e 100644 (file)
@@ -179,21 +179,23 @@ int main(int argc, char **argv){
     return 1;
   }
 
-  tm1 = timeOfDay();
   printf("C-library sprintf(\"%s\"): ", zFmt);
   fflush(stdout);
+  tm1 = timeOfDay();
   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);
+  tm2 = timeOfDay();
   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);
index dc7175ce4fee9e717bc2461da62fb0707bdaf978..3d44f38bbce5026e39fb9d33797e08bd95d32821 100644 (file)
 ** To run the test:
 **
 **    ./a.out 10000000
+**
+** Notes:
+**
+**   *  A first loop is run to measure the testing overhead.  This
+**      overhead is then subtracted from the times of subsequent loops
+**      so that the estimates are for the calls to atof() or
+**      sqlite3AtoF() only.
 */
 #include "sqlite3.h"
 #include <string.h>
@@ -162,6 +169,29 @@ static sqlite3_int64 timeOfDay(void){
 #endif
 }
 
+/*
+** Generate text of the i-th test floating-point literal.
+*/
+static int fpLiteral(int i, char *z){
+  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++] = '+';
+  }
+  z[len++] = e/100 + '0';
+  z[len++] = (e/10)%10 + '0';
+  z[len++] = e%10 + '0';
+  z[len] = 0;
+  return ex;
+}
 
 int main(int argc, char **argv){
   int i;
@@ -182,63 +212,47 @@ int main(int argc, char **argv){
     return 1;
   }
 
-  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;
-    }
-    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++] = '+';
-      }
-      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;
-      }
-    }
-    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");
-    }
+  printf("test-overhead: ");
+  fflush(stdout);
+  memset(arSum, 0, sizeof(arSum));
+  tm[2] = timeOfDay();
+  for(i=0; i<cnt; i++){
+    double r = (double)i;
+    int ex = fpLiteral(i,z);
+    arSum[ex] += r;
+  }
+  tm[2] = timeOfDay() - tm[2];
+  for(i=1; i<=400; i++) arSum[0] += arSum[i];
+  printf("%6.1f ns/test, %9.6f sec total\n", tm[2]*1e3/cnt, tm[2]*1e-6);
+
+  printf("C-lib atof():  ");
+  fflush(stdout);
+  memset(arSum, 0, sizeof(arSum));
+  tm[0] = timeOfDay();
+  for(i=0; i<cnt; i++){
+    int ex = fpLiteral(i,z);
+    arSum[ex] += atof(z);
   }
-  tm[0] -= tm[2];
-  tm[1] -= tm[2];
+  tm[0] = timeOfDay() - tm[0] - tm[2];
+  for(i=1; i<=400; i++) arSum[0] += arSum[i];
+  printf("%6.1f ns/test, %9.6f sec net", tm[0]*1e3/cnt, tm[0]*1e-6);
+  printf(", cksum: %g\n", arSum[0]);
+
+  printf("sqlite3AtoF(): ");
+  fflush(stdout);
+  memset(arSum, 0, sizeof(arSum));
+  tm[1] = timeOfDay();
+  for(i=0; i<cnt; i++){
+    double r = 0.0;
+    int ex = fpLiteral(i,z);
+    sqlite3_test_control(SQLITE_TESTCTRL_ATOF, z, &r);
+    arSum[ex] += r;
+  }
+  tm[1] = timeOfDay() - tm[1] - tm[2];
+  for(i=1; i<=400; i++) arSum[0] += arSum[i];
+  printf("%6.1f ns/test, %9.6f sec net", tm[1]*1e3/cnt, tm[1]*1e-6);
+  printf(", cksum: %g\n", arSum[0]);
+
   if( tm[0] < tm[1] ){
     printf("atof() is about %g times faster than sqlite3AtoF()\n",
            (double)tm[1]/(double)tm[0]);