1. New rtrim()

Dear Eu users,

There is the rtrim() function in
the putsxy.e lib.

This function removes zeros from
the end of a sequence.

New rtrim_() function makes the
same thing about 30% faster 
and is more simple.

--
function rtrim_(sequence s)
           for i=length(s) to 1 by -1 do
          if s[i] then 
   return s[1..i] end if end for
   return {} 
end function
--

Use it please if you need such a function.

Regards,
Igor Kachan
kinz at peterlink.ru

new topic     » topic index » view message » categorize

2. Re: New rtrim()

Colin,

Igor's unattributed brilliant idea *is* my version. Pity I did not
copyright the bloody thing as seems to be the trend these days.

But then I do not really care at all, I just hate confusion...

jiri

----- Original Message -----
From: <cetaylor at compuserve.com>
To: "EUforum" <EUforum at topica.com>
Subject: RE: New rtrim()


>
> Igor,
>
> Thanks for the suggestion.  I tried it in putsxy.e and didn't see
any
> improvement in performance, so for the moment I'll stick with Jiri's
> original version.
>
> Colin Taylor
>
>
> Igor Kachan wrote:
> > Dear Eu users,
> >
> > There is the rtrim() function in
> > the putsxy.e lib.
> >
> > This function removes zeros from
> > the end of a sequence.
> >
> > New rtrim_() function makes the
> > same thing about 30% faster
> > and is more simple.
> >
> > --
> > function rtrim_(sequence s)
> >            for i=length(s) to 1 by -1 do
> >           if s[i] then
> >    return s[1..i] end if end for
> >    return {}
> > end function
> > --
> >
> > Use it please if you need such a function.
> >
> > Regards,
> > Igor Kachan
> > kinz at peterlink.ru
> >
> >
>
>

new topic     » goto parent     » topic index » view message » categorize

3. Re: New rtrim()

Colin Taylor wrote:

> Igor,
> 
> Thanks for the suggestion.  I tried it in putsxy.e and didn't see any 
> improvement in performance, so for the moment I'll stick with Jiri's 
> original version.
> 
> Colin Taylor
> 
> 
> Igor Kachan wrote:
> > Dear Eu users,
> > 
> > There is the rtrim() function in
> > the putsxy.e lib.
> > 
> > This function removes zeros from
> > the end of a sequence.
> > 
> > New rtrim_() function makes the
> > same thing about 30% faster 
> > and is more simple.
> > 
> > --
> > function rtrim_(sequence s)
> >            for i=length(s) to 1 by -1 do
> >           if s[i] then 
> >    return s[1..i] end if end for
> >    return {} 
> > end function
> > --
> > 
> > Use it please if you need such a function.
> > 

Yes, Colin, this function is not the noticeable
one for the putsxy.e perfomance.

But try please the test below.

--program test.ex
function rtrim_(sequence s)
	      for i=length(s) to 1 by -1 do
 	     if s[i] then 
    return s[1..i] end if end for
    return {} 
end function -- rtrim_()

function rtrim(sequence s)
    integer i
    i=length(s)
    while i do
	if s[i] then exit end if
	i=i-1
    end while
    return s[1..i]
end function -- rtrim()

sequence S,s
S=repeat(repeat(0,1000),1000)

atom T
T=time()
for i=1 to 1000 do
 s=rtrim_(S[i])
end for
T=time()-T
? T

T=time()
for i=1 to 1000 do
 s=rtrim(S[i])
end for
T=time()-T
? T
--end of program

On my a 386 machine, I have

T = 10.27 with rtrim_()
T = 14.28 with rtrim()

On the Pentium, you must replace
1000 by 10000, or so, to get
the correct results.

So, there may be the cases when
rtrim_() is useful enough.

I use rtrim_() function now,
if I need to remove zeros from the 
end of a sequence.

Regards,
Igor Kachan
kinz at peterlink.ru

new topic     » goto parent     » topic index » view message » categorize

4. Re: New rtrim()

Colin,

> 
> Igor Kachan wrote:
> 
> > 
> > Yes, Colin, this function is not the noticeable
> > one for the putsxy.e perfomance.
> > 
> > But try please the test below.
> > 
> 
> Igor,
> 
> Your test program always returns an empty sequence
> instead of a slice,

I have tested

S=repeat({1,1}&repeat(0,1000),1000)

just now.

Result is

10.27 with rtrim_()
14.34 with rtrim()

> because your test sequences contain only zeros.
> This isn't a realistic 
> test, and it gives you an artificially fast score 
> for your version of 
> rtrim().

I think, this test is just the hardest
for such the program.

<snip>

Don't worry, use, thing is good enough
and very well tested now  smile

Regards,
Igor Kachan
kinz at peterlink.ru

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu