Re: getc( ) and gets( ) speed
- Posted by "Derek Parnell" <ddparnell at bigpond.com> Dec 15, 2003
- 536 views
----- Original Message ----- From: "Euman" <euman at bellsouth.net> To: <EUforum at topica.com> Subject: Re: getc( ) and gets( ) speed > > > Here you go Derek... > > This is more correct in the way it should read the ascii file... I still don't get it. The two examples are doing different things, so why are you comparing their speeds? Are they meant to be doing the same thing? The first example reads the whole file into RAM then breaks it up into 200 byte chunks. The second example reads the first 5000 lines and extacts the first 200 bytes of each line. Clearly not the same thing. What are you TRYING to do? > ------------- > include file.e > > with trace > > atom t, t1, t2, fn, lFileLen > integer lWS, lWE, crlf, line_len > sequence lFile, line > > crlf = 10 > lWS = 1 > lWE = 201 > > --trace(1) > > fn = open("trmdemo.txt", "r") > -------------------------------------------------------- > 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-1] > line_len = length(line) > lWS = lWE + 1 > lWE = lWS + 200 > end while > t2 = time()- t1 > > printf(1,"Average Time : %1.6f sec\n", t2 ) > > -------------------------------------------------------- > close(fn) > > fn = open("trmdemo.txt", "r") > -------------------------------------------------------- > t1 = time() > for i = 1 to 5000 do > line = gets(fn) > if atom(line) then > exit > end if > line = line[1..200] > end for > t2 = time()- t1 > -------------------------------------------------------- > close(fn) > > printf(1,"Average Time : %1.6f sec\n", t2 ) > > if getc(0) then end if > --------- > > > ----- Original Message ----- > From: "Derek Parnell" <ddparnell at bigpond.com> > > 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 > > -------------------------------------------------------- > > > > > > TOPICA - Start your own email discussion group. FREE! > >