Author Topic: Disk caching?  (Read 2933 times)

0 Members and 1 Guest are viewing this topic.

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Disk caching?
« on: October 23, 2019, 08:11:43 am »
Code: QB64: [Select]
  1. 'In getting to know _MEMCOPY I wrote this test to see what speed improvement I'd get by preloading all
  2. 'data and moving it around vs. loading each file as needed.  Suprisingly, there's not much difference.
  3. 'Is it disk caching that negates the "improvement"?
  4.  
  5. 'Where I do find _MEMCOPY indispensible is in shifting all elements of an array down one element, which
  6. 'isn't part of this test code.
  7.  
  8. DEFINT A-Z
  9. GOSUB init
  10.     GOSUB way_new
  11.     GOSUB way_old
  12.  
  13. init:
  14. z = 20000
  15. DIM a0(z), a1(z), a2(z), a3(z), a4(z), a5(z)
  16. DIM amem(6) AS _MEM
  17. amem(0) = _MEM(a0()): amem(1) = _MEM(a1()): amem(2) = _MEM(a2())
  18. amem(3) = _MEM(a3()): amem(4) = _MEM(a4()): amem(5) = _MEM(a5())
  19. FOR i = 1 TO 5
  20.     f$ = "h" + LTRIM$(STR$(i)) + ".dat"
  21.     s& = VARSEG(a0(0))
  22.     o& = VARPTR(a0(0))
  23.     DEF SEG = s&
  24.     BLOAD f$, o&
  25.     _MEMCOPY amem(0), amem(0).OFFSET, amem(0).SIZE TO amem(i), amem(i).OFFSET
  26. z$ = "010249042456075632380052085407"
  27. FOR i = 0 TO 14
  28.     PALETTE i + 1, VAL(MID$(z$, i * 2 + 1, 2))
  29.  
  30. way_new:
  31. t! = TIMER
  32. FOR t = 0 TO 4
  33.     FOR j = 0 TO 12
  34.         k = j * 1500
  35.         FOR i = 1 TO 5
  36.             _MEMCOPY amem(i), amem(i).OFFSET, amem(i).SIZE TO amem(0), amem(0).OFFSET
  37.             y = (i - 1) * 70
  38.             PUT (0, y), a0(k), PSET
  39.             LINE (46, y)-(90, y + 70), 0, BF
  40.             LINE (0, y)-(90, y + 13), 0, BF
  41.         NEXT i
  42.         _DISPLAY
  43.         _DELAY .04
  44.     NEXT j
  45. LOCATE 2, 30: PRINT "new ";: PRINT USING "##.####"; TIMER - t!;
  46.  
  47. way_old:
  48. t! = TIMER
  49. FOR t = 0 TO 4
  50.     FOR j = 0 TO 12
  51.         k = j * 1500
  52.         FOR i = 1 TO 5
  53.             f$ = "h" + LTRIM$(STR$(i)) + ".dat"
  54.             s& = VARSEG(a0(0))
  55.             o& = VARPTR(a0(0))
  56.             DEF SEG = s&
  57.             BLOAD f$, o&
  58.             y = (i - 1) * 70
  59.             PUT (100, y), a0(k), PSET
  60.             LINE (146, y)-(190, y + 70), 0, BF
  61.             LINE (100, y)-(190, y + 13), 0, BF
  62.         NEXT i
  63.         _DISPLAY
  64.         _DELAY .04
  65.     NEXT j
  66. LOCATE 3, 30: PRINT "old ";: PRINT USING "##.####"; TIMER - t!;
  67.  
It works better if you plug it in.