home *** CD-ROM | disk | FTP | other *** search
File List | 1989-10-30 | 2.2 KB | 90 lines |
- _PDQ: LESS BAGGAGE, FASTER CODE_
- by Bruce W. Tonkin
-
- [EXAMPLE 1]
-
- DEFINT A-Z
- DIM flags(8190)
- CLS
- PRINT "25 iterations"
- x# = TIMER
- FOR j = 1 TO 25
- count = 0
- FOR i = 0 TO 8190
- flags(i) = 1
- NEXT i
- FOR i = 0 TO 8190
- IF flags(i) THEN
- prime = i + i + 3
- k = i + prime
- WHILE k <= 8190
- flags(k) = 0
- k = k + prime
- WEND
- count = count + 1
- END IF
- NEXT i
- NEXT j
- xx# = TIMER
- PRINT USING "#### primes in ##.### seconds";count;xx#-x#
- END
-
-
- [EXAMPLE 2]
-
- rem $include: 'pdqdecl.bas'
- DIM flags(8190)
- CLS
- PRINT "25 iterations"
- start&=pdqtimer&
- FOR j = 1 TO 25
- count = 0
- FOR i = 0 TO 8190
- flags(i) = 1
- NEXT i
- FOR i = 0 TO 8190
- IF flags(i) THEN
- prime = i + i + 3
- k = i + prime
- WHILE k <= 8190
- flags(k) = 0
- k = k + prime
- WEND
- count = count + 1
- END IF
- NEXT i
- NEXT j
- done&=pdqtimer&
- tot&=(10*(done&-start&))\182 'convert timer ticks to seconds.
- frac&=(10000&*(10*(done&-start&) mod 182))\182 'and decimal.
- PRINT count;"primes in ";rtrim$(str$(tot&));".";frac&;"seconds."
- END
-
-
- [EXAMPLE 3]
-
- defint a-z 'by default, all variables are integers
- call initstr(a$,128) 'initialize a$ to 128 characters
- call initstr(b$,8192) 'buffer for file is 8K bytes
- a$=command$ 'look at the command line
- if rtrim$(a$)="" then 'no file named; give help.
- print"Syntax:"
- print"UCASE filename"
- print"The named file will be converted in place to upper-case."
- end
- end if
- open rtrim$(a$) for binary as #1 'no random files in PDQ
- size&=lof(1) 'file size
- if size&=0 then close 1:kill rtrim$(a$):end 'no such file
- where&=1 'start with the first byte
- while where&<=size& 'as long as there are bytes to read
- remains&=size&-where&+1 'how much is left?
- if remains&<8192 then call setlength(b$,remains&) '< 8192 bytes
- get 1,where&,b$ 'grab the next chunk to convert
- b$=ucase$(b$) 'upper-case it
- put 1,where&,b$ 'write it back out
- where&=where&+len(b$) 'update the file position
- wend
- end
-