Re: getc( ) and gets( ) speed
- Posted by "Euman" <euman at bellsouth.net> Dec 15, 2003
- 538 views
----- Original Message ----- From: "Derek Parnell" <ddparnell at bigpond.com> To: <EUforum at topica.com> Subject: Re: 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 Yes. > 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 > -------------------------------------------------------- what about 13,10 (crlf) from each line ending if I have 5000 lines with 201 bytes and I need only 200, I would need to bypass the crlf on each line.. This shoot holes in the theory that using getc( ) is faster than gets( ) for most things. Euman