I/O: slow or fast

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

I saw the program on i/o posted before and I changed the read routine
including a preassembled sequence in memory, just to test. See the
difference!

constant
 NONE = -1 -- one of three booleans

global function read_textfile (sequence fname)
sequence s
integer char, fh

    fh = open (fname, "r")
    if fh = NONE then
 return ""
    end if

    s = ""
    char = getc (fh)
    while char != NONE do
 s = append(s, char)
    end while

    return s
end function


global function read_text_preseq(sequence fname)
object s
atom char, fh, c
c=1
    fh = open (fname, "r")
    if fh = NONE then
 return ""
    end if

    s =repeat(0,200000)

    char = getc (fh)

    while char != NONE do
  s[c] = char
  char = getc (fh)
  c=c+1
end while

    return s
end function

object ya
atom t
t=time()
?t
ya=read_text_preseq("win32lib.ew")
?time()-t
t=time()
ya=read_textfile("win32lib.ew")
?time()-t
--?ya

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

Search



Quick Links

User menu

Not signed in.

Misc Menu