On 12/9/06 10:31 AM, Kem Tekinay at [EMAIL PROTECTED] wrote:

> I could have split the string and put that code in a loop, I guess, but I
> assume there will be a penalty there too. I'll try it and report back.

Well, that slowed it down unbelievably. With that code, it took over two
mins to process. Using a MemoryBlock instead was better, but still
practically doubled the processing time.

Finally, using a RegEx was somewhere between using IsNumeric (the slowest)
and the MemoryBlock. I assume that is because of the function call penalty.

Here is the code for splitting the characters and iterating over the array:

  dim line as string
  dim chars( -1), char as string
  do until tIn.EOF
    line =  tIn.ReadLine
    chars = line.SplitB( "" )
    dim isNumber as boolean = true
    for each char in chars
      if char < "0" or char > "9" then
        isNumber = false
        exit
      end
    next
    if isNumber then
      tOut.Write( caseStr )
      tOut.WriteLine( line )
    else
      tOut.Write( varStr )
      tOut.Write( line )
      tOut.WriteLine( closingStr )
    end if
  loop
  
This is the code for using a MemoryBlock instead:

  dim line as string
  dim m as MemoryBlock
  do until tIn.EOF
    line =  tIn.ReadLine
    dim cnt as integer = line.LenB
    m = NewMemoryBlock( cnt )
    m.StringValue( 0, cnt ) = line
    dim isNumber as boolean = true
    cnt = cnt - 1
    for i as integer = 0 to cnt
      dim v as integer = m.Byte( i )
      if v < 48 or v > 57 then
        isNumber = false
        exit
      end
    next
    if isNumber then
      tOut.Write( caseStr )
      tOut.WriteLine( line )
    else
      tOut.Write( varStr )
      tOut.Write( line )
      tOut.WriteLine( closingStr )
    end if
  loop

Finally, this is the RegEx code:
  
  dim line as string
  dim re as new RegEx
  re.SearchPattern = "^\d+$"
    do until tIn.EOF
    line =  tIn.ReadLine
    if re.Search( line, 0 ) <> nil then
      tOut.Write( caseStr )
      tOut.WriteLine( line )
    else
      tOut.Write( varStr )
      tOut.Write( line )
      tOut.WriteLine( closingStr )
    end if
  loop
  

__________________________________________________________________________
Kem Tekinay                                                 (212) 201-1465
MacTechnologies Consulting                              Fax (914) 242-7294
http://www.mactechnologies.com                        Pager (917) 491-5546

  To join the MacTechnologies Consulting mailing list, send an e-mail to:
           [EMAIL PROTECTED]






_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to