home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / ddjmag / ddj9103.zip / BUFFER.ASC < prev    next >
Text File  |  1991-02-15  |  1KB  |  59 lines

  1. _SPEEDY BUFFERING_
  2. by Bruce Tonkin
  3.  
  4. [LISTING ONE]
  5.  
  6. DEFINT A-Z
  7. CLS
  8. LINE INPUT "Name of file to read: "; filename$
  9. INPUT "Record length: "; rl
  10. buffersize = (1 + 16384 \ rl) * rl     '16K, rounded up.
  11. blocks = buffersize \ rl
  12. DIM chunk$(1 TO blocks)      'each chunk will be one record.
  13.  
  14. 'open the random file with a record length of buffersize
  15. OPEN "r", 1, filename$, buffersize
  16. filesize& = CLNG(LOF(1)) \ rl
  17.  
  18. 'set up the buffer in record-length sized chunks
  19. FOR i = 1 TO blocks
  20.    FIELD #1, dummy AS dummy$, rl AS chunk$(i)
  21.    dummy = dummy + rl
  22. NEXT i
  23.  
  24. 'open up a dummy buffer to hold the actual records
  25. OPEN "r", 2, "real.$$$", rl
  26. FIELD #2, rl AS all$
  27.  
  28. t1! = TIMER
  29. FOR i = 1 TO filesize&
  30.    GOSUB getrec    'read the buffered records
  31. NEXT i
  32. t1! = TIMER - t1!  'save the time taken
  33. CLOSE              'close the files and delete the dummy file.
  34. KILL "real.$$$"
  35.  
  36. OPEN "r", 1, filename$, rl   'now open and read unbuffered
  37. FIELD #1, rl AS all$
  38. t2! = TIMER
  39. FOR i = 1 TO filesize&
  40.    GET 1, i
  41. NEXT i
  42. t2! = TIMER - t2!
  43. CLOSE
  44. PRINT "Buffered time: "; t1!
  45. PRINT "Unbuffered time: "; t2!
  46. END
  47.  
  48. getrec:
  49. whichblock = 1 + (i - 1) \ blocks
  50. IF whichblock <> lastblock THEN
  51.     GET 1, whichblock
  52.     lastblock = whichblock
  53.     end if
  54. whichchunk = 1 + i MOD blocks
  55. LSET all$ = chunk$(whichchunk)
  56. RETURN
  57.  
  58.  
  59.