Re: getc( ) and gets( ) speed

new topic     » goto parent     » topic index » view thread      » older message » newer message

----- Original Message ----- 
From: "Euman" <euman at bellsouth.net>
To: <EUforum at topica.com>
Subject: getc( ) and gets( ) speed


> 
> 
> Hello,                                                  
>                                                         
> Can the 1st example be made any faster than the second? 

You do realize that they are not equivilent processes don't you? What is it you
are trying to achieve?

The first one doesn't actually work 'cos lWS and lWE are not initialized; and
even if they were, what is the ...
   lWS = lWE + 1                                        
   lWE = lWS + 1                                        
trying to do? Did you mean this instead...

   lWS = lWE + 1                                        
   lWE = lWS + 199

The second just grabs the first 200 chars of each line in the file.

If you are trying to break a file into 200 byte chunks, you could try this ...


atom t, t1, t2, fn, lFileLen                            
integer lChunks
sequence lFile, line                                    
  
 -- Example 1                                                       
 --------------------------------------------------------
lFileLen = seek(fn, -1)                                 
 lFileLen = where(fn)                                    
 if seek(fn, 0) then end if           
lChunks = floor((lFileLen + 1) / 200) + 1                   
 lFile = repeat(repeat(0,200), lChunks)                         
 lFile[lFileLen+1] = crlf                                
                                                         
 t1 = time()                                             
 for i=1 to lChunks do                                 
  for j = 1 to 200 do   
     lFile[i][j] = getc(fn)                                 
  end for
end for                                                 
                                                         
 t2 = time()- t1                                         
 --------------------------------------------------------


> atom t, t1, t2, fn, lFileLen                            
> integer lWS, lWE                                        
> sequence lFile, line                                    
>  
> -- Example 1                                                       
> --------------------------------------------------------
> lFileLen = seek(fn, -1)                                 
> lFileLen = where(fn)                                    
> if seek(fn, 0) then end if                              
> lFile = repeat(0, lFileLen + 1)                         
> lFile[lFileLen+1] = crlf                                
>                                                         
> t1 = time()                                             
> for i =1 to lFileLen do                                 
>     lFile[i] = getc(fn)                                 
> end for                                                 
>                                                         
> while lWE < lFileLen do                                 
>    line = lFile[lWS..lWE])                              
>    lWS = lWE + 1                                        
>    lWE = lWS + 1                                        
> end if                                                  
> t2 = time()- t1                                         
> --------------------------------------------------------
>  
> -- Example 2                                                                  
>
> --------------------------------------------------------
> t1 = time()                                             
> for i = 1 to val[2]  do                                 
>     line = gets(fn)                                     
>     if atom(line) then                                  
>        exit                                             
>     end if                                              
>     line = line[1..200]                                 
> end for                                                 
> t2 = time()- t1                                         
> --------------------------------------------------------
> 
> 
> 
> TOPICA - Start your own email discussion group. FREE!
> 
>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu