home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 12 / CD_ASCQ_12_0294.iso / maj / 659 / bc_lai10.c < prev    next >
Text File  |  1994-02-03  |  8KB  |  282 lines

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