Announcement

Collapse
No announcement yet.

speed this code up

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Matthias Kuhn
    replied
    Hi Martin,

    Your code is not runable because the include-file is missing.

    Try to use much less double unneed variables and double commands like

    put$ #2,blocksize$
    put$ #2,finalline$

    better put#2,blocksize$+finalline$

    or

    ibm1$ = chr$(0)+chr$(sizeremain+size+4)+chr$(0)+chr$(0)
    totalline$ = ibm1$+remainder$+getline$ 'add remainder line from last block to first line
    .
    better is
    .
    totalline$=chr$(0)+chr$(sizeremain+size+4)+chr$(0)+chr$(0)+_
    remainder$+getline$ 'add remainder line from last block to first line
    .
    You don`t need ibm1$ at all.
    .
    why do use the line with the tally command as all when you
    have the instr command - if there is no chr$(13) more then
    the instr command returns -1

    eg..

    do
    a%=instr(a$,start,chr$(13))
    if a%=-1 then
    exit loop
    else
    do what you want
    e.g. incr count_chr13
    end if
    loop


    try to write half of the lines within You do..loop

    Regards

    Matthias Kuhn


    [This message has been edited by Matthias Kuhn (edited September 26, 2000).]

    Leave a comment:


  • Michael Mattias
    replied
    ibm1$ = chr$(0)+chr$(sizeremain+size+4)+chr$(0)+chr$(0)
    Wherever you have a string of know length (as above), use MID$= substution rather than concatenation; also, avoid string creation when possible.


    For example, change the above to:
    Code:
    null$ = CHR$(0)
    W$ = SPACE$(4)    ' create four-byte string
    MID$(w$,1) = null$
    MID$(w$,2) = CHR$(Sizeremain+size+4)
    MID$(w$,3) = null$
    MID$(w$,4) = null$
    That should speed you up; but even faster would be to use a byte pointer approach:

    Code:
    DIM pb AS BYTE PTR
    W$ = SPACE$(4)
    pb = STRPTR(W$)
    @pb=0
    @pb[1]=SizeRemain + Size + 4
    @pb[2] = 0
    @pb[3] = 0
    Give it a try...

    MCM

    Leave a comment:


  • Mel Bishop
    replied
    The first thing I would do is change (if possible) DEFLNG to
    DEFINT. Using DEFLNG, you have all you integers defined as a
    (I think) 4-byte numbers. Changing to DEFINT or equivalent,
    will switch to a 2-byte number system which speeds things up
    considerably.

    If you can't change the whole thing to 2-byte integers, try it
    the hard way:
    y% = talley(....)
    for x% = 1 to y%
    ....
    ...
    next x%

    Using the percent sign will change that particular number to
    a 2-byte integer which, in this case, will speed up the loop.


    ------------------


    [This message has been edited by Mel Bishop (edited September 25, 2000).]

    Leave a comment:


  • Martin Myers
    started a topic speed this code up

    speed this code up

    Can anybody suggest anyway to speed this code up. It works okay, but
    its rather slow.

    deflng a-z
    DIM Arg$(2) 'Array to hold the arguments
    MaxArg% = 2 'Maximum number of arguments
    '
    ' To demonstrate CLINE, simply compile this program inside Quick Basic
    ' or from the command line.
    '
    'defsng a-z
    CLS
    CALL ParCline(Arg$(), MaxArg%, Res%)
    if arg$(1) = "" then
    cls
    Print "command Usage: pnccass <Input file> <output file>"
    end 10
    end if
    test$ = dir$(arg$(1),16) 'test for exist of file shown on command line
    if test$ = "" then
    cls
    print "input file on command line doesn't exist try again"
    print "check directory for exist of the file"
    end 10
    end if
    if arg$(2) = "" then
    cls
    print "output file on command line is missing try again"
    'print "check directory for exist of the file"
    end 10
    end if
    testx$ = dir$(arg$(2),16) 'test for exist of file shown on command line
    if testx$ <> "" then
    kill arg$(2)
    end if
    open arg$(1) for binary lock read write as #1 len = 8192
    open arg$(2) for binary as #2
    do
    finalline$ = "" 'reset variables between each block
    start = 1
    get$ #1,8000,datablock$
    y = tally(datablock$,chr$(13)) 'count the occurances of 0D in the data block
    for x = 1 to y 'use this number in the for loop to process entire block
    position = instr(start,datablock$,chr$(13))
    size = position - start
    getline$ = mid$(datablock$,start,size)
    start = start+size+2
    if x = 1 then
    ibm1$ = chr$(0)+chr$(sizeremain+size+4)+chr$(0)+chr$(0)
    totalline$ = ibm1$+remainder$+getline$ 'add remainder line from last block to first line of next block
    else
    ibm$ = chr$(0)+chr$(size+4)+chr$(0)+chr$(0)
    totalline$ = ibm$+getline$
    end if
    finalline$ = finalline$+totalline$ 'accummulate the block until then place put it to a file
    next x
    'block size in ibmvb must be in ascii characters therefore get length integer
    'divide by 256 (position 2) and get remainder of integer division (position 1) ex. ÍÍ
    finalsize = len(finalline$)
    block1 = (finalsize mod 256):block2 = (finalsize \ 256)
    blocksize$ = chr$(block1,block2,205,205)
    put$ #2,blocksize$
    put$ #2,finalline$
    remainder$ = mid$(datablock$,start) 'the data breaks at 8000 bytes the last character is probably not
    sizeremain = len(remainder$) 'a 0D0A there the for loop won't pick up so include it and add to begin of first line of next processed block
    loop until eof(1)
    close
    end
    $include "clinesub.bas"


    ------------------
Working...
X