home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / dbase / bltc13.zip / BC_LAI10.C < prev    next >
C/C++ Source or Header  |  1993-04-22  |  7KB  |  261 lines

  1.  
  2. #include <dos.h>
  3. #include <conio.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <stdarg.h>
  7. #include <time.h>
  8.  
  9. #include "BULLET.h"
  10.  
  11. /*
  12.  bb_lai10.c 31-May-92 chh
  13.  bb_lai10.c 22-Apr-93 chh fix Reindex return value to AP.stat
  14.   
  15.  --test raw speed using 32-bit long integer key, unique
  16.  1) this test uses a non-standard binary field as a sort field
  17.  2) this code is for raw speed tests--it's straight inline
  18.  
  19.  Note: memory model must be medium, large, or huge
  20.  
  21. For Turbo C 2.0:
  22.  
  23.  C>tcc -mm bc_lai10 BULLET.lib
  24.  
  25.  
  26. For Quick C 2.50 (v2.50 *must not* use ATEXITXB (define QC250 to not)):
  27.  
  28.  C>tcl -Am bc_lai10 BULLET.lib
  29.  
  30. */
  31.  
  32. /* #define QC250 sux */
  33.  
  34. struct memorypack MP;
  35. struct initpack IP;
  36. struct exitpack EP;
  37. struct fielddesctype fieldlist[2];
  38. struct createdatapack CDP;
  39. struct createkeypack CKP;
  40. struct dosfilepack DFP;
  41. struct openpack OP;
  42. struct accesspack AP;
  43. struct exitpack EP;
  44.  
  45. int    rez, level;
  46. div_t    div_rez;
  47. time_t    starttime, endtime;
  48.  
  49. char    tmpstr[129];
  50.  
  51. char     NameDAT[] = ".\\BINTEST.DBB\0";
  52. char     NameIX1[] = ".\\BINTEST.IX1\0";
  53.  
  54. char    kx1[] = "CODENUMBER\0";
  55.  
  56. unsigned handdat, handix1;
  57.  
  58. struct testrectype {
  59.     char  tag[1];
  60.     long  codenumber;
  61.     char  codename[11];
  62. }; /* 16 */
  63. struct testrectype testrec;
  64.  
  65. char    keybuffer[64];
  66.  
  67. long    recs2add;
  68. long    low;
  69. long    high;
  70. long    i;
  71.  
  72.  
  73. int main()
  74. {
  75.  
  76.    strcpy(fieldlist[0].fieldname, "CODENUMBER");
  77.    strcpy(fieldlist[0].fieldtype, "B");
  78.    fieldlist[0].fieldlen = 4;
  79.    fieldlist[0].fielddc = 0;
  80.    strcpy(fieldlist[1].fieldname, "CODENAME");
  81.    strcpy(fieldlist[1].fieldtype, "C");
  82.    fieldlist[1].fieldlen = 11;
  83.    fieldlist[1].fielddc = 0;
  84.  
  85.    /* yes, it's been a while since my last C coding, like 1985  */
  86.    /* ...just something to get used to...it's okay, though      */
  87.  
  88.    /* clrscr(); */
  89.    printf("BC_LAI10.C - LONG INT, SIGNED, UNIQUE long int, add/reindex speed test\n");
  90.    printf("--uses non-standard data files with binary field values, not DBF\n");
  91.    printf(">> USING DIRECTORY : .\\ \n\n");
  92.  
  93.    level = 100;
  94.    MP.func = MEMORYXB;
  95.    rez = BULLET(&MP);
  96.    printf("memory avail   : %lu\n",MP.memory);
  97.  
  98.    if (MP.memory < 40000l) {
  99.       rez = 8;
  100.       goto Abend;
  101.    }
  102.  
  103.    level = 110;
  104.    IP.func = INITXB;
  105.    IP.jftmode = 0;
  106.    rez = BULLET(&IP);
  107.    if (rez != 0) goto Abend;
  108.  
  109.    /* --------------------------------------------------------------------
  110.       Quick C uses a near _atexit for both medium and large standard LIBs
  111.       This is of course a bug! and it prevents the use of ATEXITXB. This
  112.       is with at least QC 2.50. If you experience a lock-up using ATEXITXB
  113.       then you know what the problem is. Easy enough to get a fix. Call MS.
  114.       And the problem is also in crt0dat. Turbo C operates correctly. */
  115.  
  116. #ifndef QC250
  117.    level = 120;
  118.    EP.func = ATEXITXB;
  119.    rez = BULLET(&EP);
  120.    if (rez != 0) goto Abend;
  121. #endif
  122.  
  123.    level = 130;                /* disregard not found errors */
  124.    DFP.func = DELETEFILEDOS;
  125.    DFP.filenameptr = NameDAT;
  126.    rez = BULLET(&DFP);
  127.    DFP.filenameptr = NameIX1;
  128.    rez = BULLET(&DFP);
  129.  
  130.    level = 1000;
  131.    CDP.func = CREATEDXB;
  132.    CDP.filenameptr = NameDAT;
  133.    CDP.nofields = 2;
  134.    CDP.fieldlistptr = fieldlist;
  135.    CDP.fileid = 255;
  136.    rez = BULLET(&CDP);
  137.    if (rez !=0) goto Abend;
  138.  
  139.    level = 1010;
  140.    OP.func = OPENDXB;
  141.    OP.filenameptr = NameDAT;
  142.    OP.asmode = READWRITE | DENYNONE;
  143.    rez = BULLET(&OP);
  144.    if (rez !=0) goto Abend;
  145.    handdat = OP.handle;
  146.  
  147.    level = 1100;
  148.    CKP.func = CREATEKXB;
  149.    CKP.filenameptr = NameIX1;
  150.    CKP.keyexpptr = kx1;
  151.    CKP.xblink = handdat;
  152.    CKP.keyflags = cLONG | cSIGNED | cUNIQUE;
  153.    CKP.codepageid = -1;
  154.    CKP.countrycode = -1;
  155.    CKP.collateptr = NULL;
  156.    rez = BULLET(&CKP);
  157.    if (rez !=0) goto Abend;
  158.  
  159.    level = 1110;
  160.    OP.func = OPENKXB;
  161.    OP.filenameptr = NameIX1;
  162.    OP.asmode = READWRITE | DENYNONE;
  163.    OP.xblink = handdat;
  164.    rez = BULLET(&OP);
  165.    if (rez !=0) goto Abend;
  166.    handix1 = OP.handle;
  167.  
  168.    AP.func = ADDRECORDXB;
  169.    AP.handle = handdat;
  170.    AP.recptr = &testrec;
  171.    AP.keyptr = keybuffer;
  172.    AP.nextptr = NULL;
  173.  
  174.    strcpy(testrec.tag," \0");
  175.    strcpy(testrec.codename, "xxxSAMExxxx\0");
  176.  
  177.    printf("Recs to add/reindex: ");
  178.    gets(tmpstr);
  179.    recs2add = atol(tmpstr);
  180.    if (recs2add == 0L) recs2add = 5L;
  181.  
  182.    level = 1200;
  183.    low = -3L;
  184.    high = low + recs2add - 1L;
  185.    printf("Adding %ld records ( keys %ld to %ld )... ",recs2add,low,high);
  186.  
  187.    time(&starttime);
  188.    for (i = low; i < (recs2add+low); i++) {
  189.       testrec.codenumber = i;
  190.       rez = BULLET(&AP);
  191.       if (rez !=0) goto Abend;
  192.    }
  193.    time(&endtime);
  194.    printf("%lu secs.\n",(endtime - starttime));
  195.  
  196.    level = 1210;
  197.    printf("Reindexing... ");
  198.    AP.func = REINDEXXB;
  199.    AP.handle = handix1;
  200.    time(&starttime);
  201.    rez = BULLET(&AP);
  202.    time(&endtime);
  203.    if (rez != 0) {
  204.       rez = AP.stat;    /* MUST take AP.stat since a xaction routine */
  205.       goto Abend;       /* see docs and !README2.TXT for more */
  206.    }
  207.    printf("%lu secs\n\n",(endtime - starttime));
  208.  
  209.    level = 1300;
  210.    AP.func = GETFIRSTXB;
  211.    rez = BULLET(&AP);
  212.    printf("  The first 5 key/recs\n");
  213.    printf("%7lu %7ld %.11s\n",AP.recno,testrec.codenumber,testrec.codename);
  214.    for (i=1;i < 5; i++) {
  215.       if (rez != 0) break;
  216.       AP.func = GETNEXTXB;
  217.       rez = BULLET(&AP);
  218.       printf("%7lu %7ld %.11s\n",AP.recno,testrec.codenumber,testrec.codename);
  219.    }
  220.    if (rez == 202) rez = 0;
  221.    if (rez != 0) goto Abend;
  222.    puts(" ");
  223.  
  224.    level = 1310;
  225.    AP.func = GETLASTXB;
  226.    rez = BULLET(&AP);
  227.    printf("  The last 5 key/recs\n");
  228.    printf("%7lu %7ld %.11s\n",AP.recno,testrec.codenumber,testrec.codename);
  229.    for (i=1;i < 5; i++) {
  230.       if (rez != 0) break;
  231.       AP.func = GETPREVXB;
  232.       rez = BULLET(&AP);
  233.       printf("%7lu %7ld %.11s\n",AP.recno,testrec.codenumber,testrec.codename);
  234.    }
  235.    if (rez == 203) rez = 0;
  236.    if (rez != 0) goto Abend;
  237.  
  238.    puts("Okay.");
  239.    EP.func = EXITXB;
  240.    rez = BULLET(&EP);
  241.    return(0);
  242.    /* program exit */
  243.  
  244.  
  245.    /*----------------------------------------------*/
  246.    /* that's right, we go to a termination routine */
  247.  
  248. Abend:
  249.    printf("Error: %u at level %u while performing ",rez,level);
  250.    switch (level) {
  251.    case 100:
  252.       printf("a memory request of 140K.\n");
  253.       break;
  254.    default:
  255.       printf("(See source)\n");    /* just check the source */
  256.    }
  257.  
  258.    exit(1);
  259. }
  260.  
  261.