home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / db3tips2.zip / DCRUNCH.TXT < prev    next >
Text File  |  1986-07-01  |  11KB  |  323 lines

  1.                     dCRUNCH for Program Speed
  2.               (PC Magazine Vol 5 No 13 Power User)
  3.  
  4.      In both "Pseudo Compiler for dBASE II" (PC Mag Vol 5 No 5 Power
  5. User) and "dBASE Speed Tips" (PC Mag Vol 5 No 1 Power User), the point
  6. is made that dBASE programs will execute faster if leading and trailing
  7. spaces, blank lines, and "*" lines are stripped out and if everything
  8. (except quoted text) is capitalized.  (See the file DB3MISC.TXT for
  9. the articles cited here.)
  10.      To facilitate the necessary file preparation, dCRUNCH.BAT and
  11. dSTRIP.COM will convert a 64K command file in under 6 seconds.  Before
  12. running programs through the DOS filter, edit out any single apostrophes
  13. inside NOTE or TEXT/ENDTEXT statements, since capitalization is based
  14. on pairs of apostrophes, double quote, or brackets.  Note also that
  15. everything inside a TEXT/ENDTEXT statement will be capitalized and
  16. left-justified unless you first enclose it in quotes, then edit out
  17. the quotes later.
  18.      The syntax for the command is:
  19.  
  20. DCRUNCH [d:][path][filename]
  21.  
  22. and you should omit the .PRG filename extension.
  23.      dBASE's interpreter is its weakest (slowest) link.  When a command
  24. is issued, the interpreter 1) parses the full command line; 2) discards
  25. leading spaces; 3) indexes to the first space to identify the verb;
  26. 4) truncates the string if it's longer than four characters; 5) converts
  27. it to uppercase; 6) searches its lookup table of initial verbs; and,
  28. 7) gets down to business.  If you write a long NOTE or "*" comment, the
  29. interpreter looks at every byte, savors a delicate sample, then spits
  30. it out.  The same applies when you add a comment after ENDIF or ENDDO,
  31. or when you indent command lines for legibility.
  32.      Take, for example, this simple iterative loop:
  33.  
  34. variable_x=0
  35. DO WHILE variable_x<1000
  36.      variable_x=variable_x+1
  37.      *This is a long comment line
  38.      *explaining what's going on
  39. ENDDO
  40.  
  41.      dCRUNCH shortens processing of this loop over 25 percent -- from
  42. 58 to 42 seconds.  The biggest offender is the"*" line -- 13 seconds;
  43. a long comment tacked on to the ENDDO will have the same effect.
  44. Shortening "variable_x" to "x" shaves another 6 seconds.
  45.      There is no measurable difference is one blank line is added, but
  46. a large overhead begins to accumulate with each additional blank line.
  47. Five blank lines increase execution time of 1,000 loops by 11 seconds.
  48.      dCRUNCH's side effects are substantial.  A program that is all-
  49. capitalized and left-justified without comments or mnemonic variable
  50. names is awful to read and a nightmare to modify 6 months later.  And,
  51. in most applications, a few extra milliseconds inside a loop is the
  52. least of your problems.  But if you need maximum speed inside an
  53. intensive loop -- like passing each record in a file -- dCRUNCH is
  54. just the ticket.
  55.  
  56. - - - - -
  57. dCRUNCH.BAT:
  58.  
  59. ECHO OFF
  60. REM dCRUNCH.BAT   Speeds dBASE routines.   Calls dSTRIP.COM
  61. IF %1/==/ GOTO noparm
  62. IF NOT EXIST dstrip.com GOTO nocom
  63. IF EXIST %1.prg GOTO strip
  64. ECHO -----
  65. ECHO File %1.PRG not found
  66. IF EXIST %1 ECHO Please specify the file without .PRG extension
  67. GOTO noparm
  68. :strip
  69. IF NOT EXIST %1.prk GOTO work
  70. ECHO -----
  71. ECHO A back-up file %1.PRK already exists and will be overwritten.
  72. ECHO Hit CTRL-BREAK followed by Y to interrupt or ...
  73. PAUSE
  74. DEL %1.prg
  75. :work
  76. ECHO Streamlining %1.prg.  Original version is saved as %1.prk
  77. REN %1.prg %1.prk
  78. dstrip <%1.prk >%1.prg
  79. GOTO end
  80. :noparm
  81. ECHO SYNTAX:     DCRUNCH [d:][path][filename]   (omit ".prg" extension)
  82. GOTO end
  83. :nocom
  84. ECHO File DSTRIP.COM not found.
  85. :end
  86.  
  87. - - - - -
  88. DSTRIP.ASM (to create DSTRIP.COM):
  89.  
  90. ; DSTRIP - DOS filter to remove leading and trailing blanks, blank
  91. ;          lines and comment lines from dBASE command files, and to
  92. ;          capitalize text not in quotation marks.
  93. ;
  94. comseg  segment para public 'code'
  95.         assume  cs:comseg,ds:comseg,es:comseg,ss:comseg
  96.         org     100h
  97. start   proc    far
  98.         cld
  99.         mov     bl,00000001b    ;the bits in the BL register will hold
  100.                                 ;the following information when set to 1:
  101.                                 ;0-bit  only tabs and blanks encountered
  102.                                 ;       in current line
  103.                                 ;1-bit  a '*' encountered as first
  104.                                 ;       character of line
  105.                                 ;4-bit  char inside 'single' quotes
  106.                                 ;5-bit  char inside "double" quotes
  107.                                 ;6-bit  last char was linefeed
  108.                                 ;7-bit  last char in *-line was a ';'
  109.         xor     dx,dx           ;DX will count blanks/tabs after a char
  110. load:   push    bx              ;save registers and
  111.         push    dx
  112.         mov     dx,offset data  ;read into memory
  113.         mov     cx,64000        ;64K bytes
  114.         xor     bx,bx           ;from standard input
  115.         mov     ah,3fh          ;with DOS function call
  116.         int     21h
  117.         pop     dx              ;restore registers
  118.         pop     bx
  119.         or      ax,ax           ;AX has number of bytes read; test for 0
  120.         jnz     load0
  121.         jmp     done
  122. load0:  mov     cx,ax           ;move count into CX
  123.         mov     si,offset data  ;and position index registers for
  124.         mov     di,offset data  ;a string move
  125. scan0:  lodsb                   ;fetch a byte into AL
  126.         cmp     al,26           ;end of file?
  127.         jz      store           ;if so, store and get out
  128.         test    bl,01000000b    ;LF on previous fetch?
  129.         jz      next            ;if not, skip
  130.         or      bl,1            ;set beginning of line bit
  131.         and     bl,10111111b    ;and reset the LF bit
  132.         test    bl,10000000b    ;a ';' at end of line?
  133.         jnz     next0           ;if yes, skip
  134.         and     bl,11111101b    ;otherwise reset '*'-bit
  135. next0:  and     bl,01111111b    ;reset ';'-bit
  136. next:   cmp     al,59           ;a ';'?
  137.         jnz     next1           ;if not, skip
  138.         or      bl,10000000b    ;set ';'-bit
  139.         jmp     short next5     ;and do loop routine
  140. next1:  cmp     al,32           ;blank?
  141.         jz      count           ;if yes, check whether to count it
  142.         cmp     al,09           ;tab?
  143.         jnz     next2           ;if not, skip count
  144. count:  test    bl,11b          ;are we at beginning of line or in a '*'-line?
  145.         jnz     loop            ;if yes, loop and omit
  146.         inc     dx              ;otherwise count the blank/tab
  147.         jmp     short store     ;and store it
  148. next2:  cmp     al,13           ;CR?
  149.         jz      out             ;if yes go to end of line routine
  150. next3:  cmp     al,10           ;LF?
  151.         jnz     next4           ;if not, go on checking
  152.         or      bl,01000000b    ;set end of line bit
  153.         jmp     short out       ;and go to end of line routine
  154. next4:  test    bl,1            ;have we seen any nonblank/tab char before?
  155.         jz      next6           ;if yes, ignore the next step
  156.         cmp     al,42           ;a '*'?
  157.         jnz     next5           ;if not, skip
  158.         or      bl,10b          ;otherwise set the '*'-bit
  159. next5:  and     bl,11111110b    ;and in either case we have nonblank/tab char
  160. next6:  xor     dx,dx           ;set blank/tab count to 0
  161. out:    test    bl,11b          ;are we at beginning of line or in a '*'-line?
  162.         jnz     loop            ;if so, ignore (includes CR/LF of blank lines)
  163.         sub     di,dx           ;DX is non-zero only if we encountered a CR
  164.         xor     dx,dx           ;reset DX to 0
  165.         and     bl,01111111b    ;reset ';'-bit
  166. caps0:  jmp     short caps      ;capitalize
  167. store:  stosb                   ;store char
  168. loop:   cmp     al,26           ;test for end of file
  169.         loopnz  scan0           ;and loop for next fetch
  170.         push    ax              ;save registers
  171.         push    bx
  172.         push    dx
  173.         mov     dx,offset data  ;compute the numbers of bytes stored
  174.         mov     cx,di
  175.         sub     cx,dx           ;in CX, and
  176.         mov     bx,01           ;write to standard output
  177.         mov     ah,40h          ;with DOS function call
  178.         int     21h
  179.         pop     dx
  180.         pop     bx
  181.         pop     ax
  182.         cmp     al,26           ;end of file?
  183.         jz      done
  184.         jmp     load            ;if not, read another 64K bytes
  185. done:   int     20h             ;end program
  186. caps:   cmp     al,39           ;single quote?
  187.         jnz     quot            ;if not, check double quote
  188.         test    bl,100000b      ;is double quote bit set?
  189.         jnz     store           ;if yes, ignore
  190.         xor     bl,010000b      ;(re-)set single quote bit
  191.         jmp     short store
  192. quot:   cmp     al,34           ;double quote?
  193.         jnz     caps01          ;if not, skip
  194.         xor     bl,00100000b    ;(re-)set double-quote bit
  195.         jmp     short store
  196. caps01: test    bl,00110000b    ;any quote-bits set?
  197.         jnz     store           ;if so, don't capitalize
  198. caps1:  cmp     al,97           ;below 'a'?
  199.         jb      store           ;if so, leave it alone
  200. caps2:  cmp     al,122          ;above 'z'?
  201.         ja      store           ;if so, don't change
  202. caps3:  and     al,5fh          ;otherwise capitalize
  203. out2:   jmp     short store
  204. start   endp
  205. data:
  206. comseg  ends
  207.         end     start
  208.  
  209.  
  210. - - - - -
  211.      You can use DEBUG to create DSTRIP.COM by issuing the command:
  212.  
  213. DEBUG < DSTRIP.INP
  214.  
  215. with the following.  DEBUG will use DSTRIP.INP as its input to create
  216. the .COM file.
  217.  
  218. N DSTRIP.COM
  219. A
  220. CLD
  221. MOV     BL,01
  222. XOR     DX,DX
  223. PUSH    BX
  224. PUSH    DX
  225. MOV     DX,01CE
  226. MOV     CX,FA00
  227. XOR     BX,BX
  228. MOV     AH,3F
  229. INT     21
  230. POP     DX
  231. POP     BX
  232. OR      AX,AX
  233. JNZ     011C
  234. JMP     01A4
  235. MOV     CX,AX
  236. MOV     SI,01CE
  237. MOV     DI,01CE
  238. LODSB
  239. CMP     AL,1A
  240. JZ      0184
  241. TEST    BL,40
  242. JZ      013F
  243. OR      BL,01
  244. AND     BL,BF
  245. TEST    BL,80
  246. JNZ     013C
  247. AND     BL,FD
  248. AND     BL,7F
  249. CMP     AL,3B
  250. JNZ     0148
  251. OR      BL,80
  252. JMP     0171
  253. CMP     AL,20
  254. JZ      0150
  255. CMP     AL,09
  256. JNZ     0158
  257. TEST    BL,03
  258. JNZ     0185
  259. INC     DX
  260. JMP     0184
  261. CMP     AL,0D
  262. JZ      0176
  263. CMP     AL,0A
  264. JNZ     0165
  265. OR      BL,40
  266. JMP     0176
  267. TEST    BL,01
  268. JZ      0174
  269. CMP     AL,2A
  270. JNZ     0171
  271. OR      BL,02
  272. AND     BL,FE
  273. XOR     DX,DX
  274. TEST    BL,03
  275. JNZ     0185
  276. SUB     DI,DX
  277. XOR     DX,DX
  278. AND     BL,7F
  279. JMP     01A6
  280. STOSB
  281. CMP     AL,1A
  282. LOOPNZ  0124
  283. PUSH    AX
  284. PUSH    BX
  285. PUSH    DX
  286. MOV     DX,01CE
  287. MOV     CX,DI
  288. SUB     CX,DX
  289. MOV     BX,0001
  290. MOV     AH,40
  291. INT     21
  292. POP     DX
  293. POP     BX
  294. POP     AX
  295. CMP     AL,1A
  296. JZ      01A4
  297. JMP     0105
  298. INT     20
  299. CMP     AL,27
  300. JNZ     01B4
  301. TEST    BL,20
  302. JNZ     0184
  303. XOR     BL,10
  304. JMP     0184
  305. CMP     AL,22
  306. JNZ     01BD
  307. XOR     BL,20
  308. JMP     0184
  309. TEST    BL,30
  310. JNZ     0184
  311. CMP     AL,61
  312. JB      0184
  313. CMP     AL,7A
  314. JA      0184
  315. AND     AL,5F
  316. JMP     0184
  317.  
  318. RCX
  319. 0CE
  320. W
  321. Q
  322.  
  323.