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