home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / CONTRIB / MBASE / MBASE51.TAR / mbase51 / examples / example5.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-04  |  2.7 KB  |  129 lines

  1. /*
  2.  * Note that this relation is encrypted; use "key" to look up
  3.  * the information added.
  4.  *
  5.  */
  6.  
  7. #include <mbase.h>
  8. #include "example5.h"
  9.  
  10. /*
  11.  * PROTOTYPES -----------------------------------------------------------------
  12.  *
  13.  */
  14.  
  15.    void main XARGS( (void) );
  16.  
  17.  
  18. /*
  19.  * CODE -----------------------------------------------------------------------
  20.  *
  21.  */
  22.  
  23. void
  24. main ()
  25. {
  26.    relation *rel;
  27.    example5  rec;
  28.    mb_time   start;
  29.    char      yesno[10];
  30.    int       i;
  31.  
  32.    setbuf (stdout, NULL);  /* So "."'s will print immediately */
  33.  
  34.  
  35.    if ((rel = mb_inc ("example5", "key")) == RNULL)
  36.       {
  37.       fprintf (stderr, "mb_inc() failed: %s\n", mb_error);
  38.       mb_exit (1);
  39.       }
  40.  
  41.  
  42. /*
  43.  * First, let's see how long it takes to add 50 records...
  44.  *
  45.  */
  46.  
  47.    printf ("adding 100 records with mb_add()...\n");
  48.  
  49.    start = curtime();
  50.    for (i = 0; i < 100; i++)
  51.       {
  52.       rec.num = (ushort)( rand() % 0xFFFF );
  53.       if (mb_add (rel, &rec) != MB_OKAY)
  54.          {
  55.          fprintf (stderr, "mb_add() failed: %s\n", mb_error);
  56.          mb_exit (2);
  57.          }
  58.       }
  59.  
  60.    printf ("...that took %ld seconds\n", elap_t (start));
  61.  
  62.  
  63. /*
  64.  * Now, let's see how long it takes to add five times that with mb_add_q()...
  65.  *
  66.  */
  67.  
  68.    printf ("adding 500 records with mb_add_q()...\n");
  69.  
  70.    start = curtime();
  71.    for (i = 0; i < 500; i++)
  72.       {
  73.       rec.num = (ushort)( rand() % 0xFFFF );
  74.       if (mb_add_q (rel, &rec) != MB_OKAY)
  75.          {
  76.          fprintf (stderr, "mb_add() failed: %s\n", mb_error);
  77.          mb_exit (2);
  78.          }
  79.       }
  80.  
  81.    printf ("...that took %ld seconds\n", elap_t (start));
  82.  
  83.  
  84. /*
  85.  * And see if the user wants to index all those records...
  86.  *
  87.  */
  88.  
  89.    printf ("\n");
  90.    printf ("there are %d record(s) to be indexed...\n", mb_num_q(rel));
  91.    printf ("index them now? ");
  92.    gets (yesno);
  93.    printf ("\n");
  94.  
  95.    if (yesno[0] != 'Y' && yesno[0] != 'y')
  96.       {
  97.       printf ("no?  okay.\n\n");
  98.       printf ("use 'MBDIAG -k key example5' to index them (you need the\n");
  99.       printf ("'-k key' bit because this relation is encrypted)--and see\n");
  100.       printf ("how long it takes.  Then 'build -q example5' and re-run\n");
  101.       printf ("this program, and answer 'y'\n");
  102.       }
  103.    else
  104.       {
  105.       printf ("okay... this could take a bit:\n\n");
  106.  
  107.       start = curtime();
  108.       do {
  109.          mb_xfer (rel);
  110.          printf (".");
  111.          }
  112.       while (mb_errno == MB_OKAY);
  113.  
  114.       if (mb_errno != MB_NO_QUEUE)
  115.          {
  116.          fprintf (stderr, "mb_xfer() failed: %s\n", mb_error);
  117.          mb_exit (2);
  118.          }
  119.       printf ("\ndone!  that took %d seconds.\n\n", elap_t(start));
  120.  
  121.       printf ("Try 'build -q example5', and re-run this without saying Yes.\n");
  122.       printf ("Then use MBDIAG to index all those records...\n");
  123.       }
  124.  
  125.    mb_rmv (rel);
  126.    mb_exit (0);
  127. }
  128.  
  129.