Re: getc( ) and gets( ) speed

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

Kat wrote:

> On 16 Dec 2003, at 8:44, Derek Parnell wrote:

<snip>

>> But think about it, you need to call getc() for each and every character
>> inside
>> some form of (slow) Euphoria loop; but gets() only needs to be called for
>> each
>> line (multiple characters per time), so in many circumstances gets() will be
>> faster then getc(). However, gets() only works for text files, it makes a
>> mess
>> of binary files.
>
> Which makes even more sense to use fget() (or something like that) to grab
> the whole file from the OS into a sequence, glom the whole thing at once.

<snip>

Yes.
Once upon a time blink I thought that reading just a number of bytes from
a file should be faster then reading the file in text mode, because text
mode needs some interpretation. Then I realised, that the following
little program

-----------=-----------=------------=------------=----------=-----------
global function read_text_file (string filename)
   integer fn
   sequence content
   object line

   fn = open(file, "r")
   if fn = -1 then
      return -1
   end if

   content = ""
   line = gets(fn)
   while sequence(line) do
      content &= line
      line = gets(fn)
   end while
   close(fn)
   return content
end function
-----------=-----------=------------=------------=----------=-----------

is on my PC almost twice(!) as fast as doing the same, using get_bytes()
instead of gets(). That's strange IMHO.

Regards,
   Juergen

-- 
 /"\  ASCII ribbon campain  |    |\      _,,,---,,_
 \ /  against HTML in       |    /,`.-'`'    -.  ;-;;,_
  X   e-mail and news,      |   |,4-  ) )-,_..;\ (  `'-'
 / \  and unneeded MIME     |  '---''(_/--'  `-'\_)

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

Search



Quick Links

User menu

Not signed in.

Misc Menu