From: drh <> Date: Fri, 27 Mar 2026 14:19:01 +0000 (+0000) Subject: Update fp-speed-1.c and fp-speed-2.c to include its own timers, so that it X-Git-Tag: major-release~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2dd3b4a646070333f14d845cea9cf5567d2c1abf;p=thirdparty%2Fsqlite.git Update fp-speed-1.c and fp-speed-2.c to include its own timers, so that it works on platforms that lack the "time" command. FossilOrigin-Name: 9b083070de2d782fe1db62652af8f3cd48abe16b55b974f3927b738e3d914887 --- diff --git a/manifest b/manifest index 45fb8844fd..576ae58ea1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sfp-speed-2.c\sperformance\stest\sprogram. -D 2026-03-27T14:03:41.832 +C Update\sfp-speed-1.c\sand\sfp-speed-2.c\sto\sinclude\sits\sown\stimers,\sso\sthat\sit\nworks\son\splatforms\sthat\slack\sthe\s"time"\scommand. +D 2026-03-27T14:19:01.594 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 a3a59b8822857918ed3aa90f195884c00f542efa8afd7529188550f948cb0995 -F test/fp-speed-2.c 2f3b208ce8a6324a0fd74321a9040f46f0e09fc4d0dd20e721517e12704dde31 +F test/fp-speed-1.c d5a2e3ab88b190fdbc7835b33ae78ac15967f6012907cb28ed3f40b76e21786e +F test/fp-speed-2.c af6b1fbd368c3981566b14e3c1932badf31c65624456e10dd36433ef3be6b8fb F test/fpconv1.test 63f352682fa65601a326563ad633086df6ab194e6ed5e7366786f38a525a7fd7 F test/fptest01.sql 210562ad8d5a7895f26273dd3be56561a41bcb51d78a28a337af0f1ceaa3bb8d 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 cd472d7c85f3fda54bba5166eae72b5f9b86861c4a1160583e8ee902ba992255 -R f34e0fa460503e1caaba2303ab84843f +P b788256f1980531e7abb15c5fbcdd40ae166f091aea28f449c0407105ddf1aa4 +R f42aecab7436b20b96c2b346a6e94f0e U drh -Z 1b7a44c07f55210ac3d9d7d1d33633e4 +Z b1baed1b56fbdbc43bde1513944e1825 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e55f842ff4..dfa6cc19ba 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b788256f1980531e7abb15c5fbcdd40ae166f091aea28f449c0407105ddf1aa4 +9b083070de2d782fe1db62652af8f3cd48abe16b55b974f3927b738e3d914887 diff --git a/test/fp-speed-1.c b/test/fp-speed-1.c index 79c0721327..2cd0af9050 100644 --- a/test/fp-speed-1.c +++ b/test/fp-speed-1.c @@ -13,9 +13,18 @@ ** ** To run the test: ** -** time ./a.out 0 10000000 <-- standard library -** time ./a.out 1 10000000 <-- SQLite +** ./a.out 0 10000000 <-- standard library +** ./a.out 1 10000000 <-- SQLite */ +#include "sqlite3.h" +#include +#include +#ifdef _WIN32 +# include +#else +# include +#endif + static double aVal[] = { -1.0163830486285643089e+063, +0.0049243807391586981e-019, @@ -120,14 +129,44 @@ static double aVal[] = { }; #define NN (sizeof(aVal)/sizeof(aVal[0])) -#include "sqlite3.h" -#include -#include +/* Return the current wall-clock time in microseconds since the +** Unix epoch (1970-01-01T00:00:00Z) +*/ +static sqlite3_int64 timeOfDay(void){ +#if defined(_WIN64) && _WIN32_WINNT >= _WIN32_WINNT_WIN8 + sqlite3_uint64 t; + FILETIME tm; + GetSystemTimePreciseAsFileTime(&tm); + t = ((sqlite3_uint64)tm.dwHighDateTime<<32) | + (sqlite3_uint64)tm.dwLowDateTime; + t += 116444736000000000LL; + t /= 10; + return t; +#elif defined(_WIN32) + static sqlite3_vfs *clockVfs = 0; + sqlite3_int64 t; + if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(0); + if( clockVfs==0 ) return 0; /* Never actually happens */ + if( clockVfs->iVersion>=2 && clockVfs->xCurrentTimeInt64!=0 ){ + clockVfs->xCurrentTimeInt64(clockVfs, &t); + }else{ + double r; + clockVfs->xCurrentTime(clockVfs, &r); + t = (sqlite3_int64)(r*86400000.0); + } + return t*1000; +#else + struct timeval sNow; + (void)gettimeofday(&sNow,0); + return ((sqlite3_int64)sNow.tv_sec)*1000000 + sNow.tv_usec; +#endif +} int main(int argc, char **argv){ int i; int cnt; int fg; + sqlite3_int64 tm; char zBuf[1000]; if( argc!=3 ){ @@ -137,6 +176,7 @@ int main(int argc, char **argv){ 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); @@ -153,5 +193,7 @@ int main(int argc, char **argv){ break; } } + tm = timeOfDay() - tm; + printf("Elapse time: %lld.%06lld seconds\n", tm/1000000, tm%1000000); return 0; } diff --git a/test/fp-speed-2.c b/test/fp-speed-2.c index f5116f628c..e3c8cd7878 100644 --- a/test/fp-speed-2.c +++ b/test/fp-speed-2.c @@ -13,13 +13,19 @@ ** ** To run the test: ** -** time ./a.out 0 10000000 <-- standard library -** time ./a.out 1 10000000 <-- SQLite -** time ./a.out 2 10000000 <-- test program overhead +** ./a.out 0 10000000 <-- standard library +** ./a.out 1 10000000 <-- SQLite +** ./a.out 2 10000000 <-- test program overhead */ +#include "sqlite3.h" #include #include #include +#ifdef _WIN32 +# include +#else +# include +#endif static const char *aVal[] = { "-1.01638304862856430", @@ -125,15 +131,45 @@ static const char *aVal[] = { }; #define NN (sizeof(aVal)/sizeof(aVal[0])) +/* Return the current wall-clock time in microseconds since the +** Unix epoch (1970-01-01T00:00:00Z) +*/ +static sqlite3_int64 timeOfDay(void){ +#if defined(_WIN64) && _WIN32_WINNT >= _WIN32_WINNT_WIN8 + sqlite3_uint64 t; + FILETIME tm; + GetSystemTimePreciseAsFileTime(&tm); + t = ((sqlite3_uint64)tm.dwHighDateTime<<32) | + (sqlite3_uint64)tm.dwLowDateTime; + t += 116444736000000000LL; + t /= 10; + return t; +#elif defined(_WIN32) + static sqlite3_vfs *clockVfs = 0; + sqlite3_int64 t; + if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(0); + if( clockVfs==0 ) return 0; /* Never actually happens */ + if( clockVfs->iVersion>=2 && clockVfs->xCurrentTimeInt64!=0 ){ + clockVfs->xCurrentTimeInt64(clockVfs, &t); + }else{ + double r; + clockVfs->xCurrentTime(clockVfs, &r); + t = (sqlite3_int64)(r*86400000.0); + } + return t*1000; +#else + struct timeval sNow; + (void)gettimeofday(&sNow,0); + return ((sqlite3_int64)sNow.tv_sec)*1000000 + sNow.tv_usec; +#endif +} -#include "sqlite3.h" -#include -#include int main(int argc, char **argv){ int i; int cnt; int fg; + sqlite3_int64 tm; double arSum[401]; char z[1000]; @@ -144,6 +180,7 @@ int main(int argc, char **argv){ 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; @@ -193,6 +230,8 @@ int main(int argc, char **argv){ } } for(i=1; i<=400; i++) arSum[0] += arSum[i]; - printf("Grand total: %g\n", arSum[0]); + printf("Checksum: %g\n", arSum[0]); + tm = timeOfDay() - tm; + printf("Elapse time: %lld.%06lld seconds\n", tm/1000000, tm%1000000); return 0; }