home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / QBAS / IMB9008.ZIP / TESTTABL.BAS < prev    next >
BASIC Source File  |  1990-07-12  |  2KB  |  72 lines

  1. DECLARE FUNCTION RandomSymbol$ (Parms AS ANY)
  2. '----------------------------------------------------------------
  3. ' Test the lookup table routines
  4. '----------------------------------------------------------------
  5. DEFINT A-Z
  6.  
  7.  
  8. '$INCLUDE: 'TABLMNGR.BI'
  9.  
  10.   CLS
  11.   RANDOMIZE TIMER
  12.   CONST True = -1, False = 0
  13.  
  14. 'Initialize the table values
  15.  
  16.   DIM Sym AS SymbolTableParameters
  17.   Sym.Delim = "\": Sym.SWidth = 10: NbrEnt = 1000
  18.   Successful = SymCreateTbl(SymTbl$, Sym, NbrEnt)
  19.  
  20. 'Start the test
  21.  
  22.   IF Successful THEN
  23.  
  24. 'Fill the array
  25.  
  26.     PRINT "Filling table for test with"; NbrEnt; "entries ";
  27.     A! = TIMER
  28.     FOR I = 1 TO NbrEnt
  29. L:    Symbol$ = RandomSymbol$(Sym)
  30.       IF NOT SymDefine(SymTbl$, Symbol$, Sym) THEN
  31.         BEEP  'Collision
  32.         GOTO L
  33.       END IF
  34.       LOCATE 2, 1: PRINT USING " #### \        \"; I; Symbol$
  35.     NEXT I
  36.     B! = TIMER
  37.     PRINT "Elapsed time for setting";
  38.     PRINT USING " ##,### entries: ###.##"; NbrEnt; B! - A!
  39.     PRINT USING "##.##### "; (B! - A!) / NbrEnt;
  40.     PRINT "seconds per create"
  41.  
  42.     PRINT "Lookup the last entry:"; NbrEnt; "times"
  43.     TestSym$ = SymGet$(SymTbl$, Sym.NbrEntries, Sym)
  44.  
  45. 'Search for the last element
  46.  
  47.     PRINT "Looking for "; TestSym$
  48.     A! = TIMER
  49.     FOR I = 1 TO NbrEnt
  50.       S% = SymDefined(SymTbl$, TestSym$, Sym)
  51.     NEXT I
  52.     B! = TIMER
  53.     PRINT "Elapsed time for lookups";
  54.     PRINT USING " ##,### entries: ###.##"; NbrEnt; B! - A!
  55.     PRINT USING "##.##### "; (B! - A!) / NbrEnt;
  56.     PRINT "seconds per lookup"
  57.   ELSE
  58.     PRINT "Couldn't pre-allocate table"
  59.   END IF
  60. END
  61.  
  62. FUNCTION RandomSymbol$ (Parms AS SymbolTableParameters)
  63.   R$ = ""
  64.   FOR I = 1 TO INT((Parms.SWidth - 5 + 1) * RND + 5)
  65. L1: C% = INT(26 * RND + 65)   'A to Z
  66.     IF C% = ASC(Parms.Delim) THEN GOTO L1:
  67.     R$ = R$ + CHR$(C%)
  68.   NEXT I
  69.   RandomSymbol$ = R$
  70. END FUNCTION
  71.  
  72.