Remove the remove

123 views
Skip to first unread message

mic...@preece.net

unread,
Feb 16, 2007, 6:42:02 AM2/16/07
to jBASE
When I first started cutting code to process data in a dynamic array I
would always do it this way:

ATTCNT=DCOUNT(MY.ARRAY,AM)
FOR ATT=1 TO ATTCNT
ATTVAL=MY.ARRAY<ATT>
(do something)
NEXT ATT

Then, when I did my first contract at a Pr1me Information site, I was
told it was much more efficient to do it this way instead:

LOOP
REMOVE ATTVAL FROM MY.ARRAY SETTING MORE
WHILE ATTVAL:MORE # "" DO
(something)
REPEAT

As with a lot of things, I felt more comfortable doing things the
'old' way but, sure enough, tests proved that the
LOOP...REMOVE...REPEAT construct was indeed more efficient.

In the course of googling back over previous posts in here I noticed,
in this thread http://tinyurl.com/2jyr9e that Jim said that, because
of the way jBASE does things, REMOVE isn't any more efficient.

I wrote, compiled and ran this code:

ARR=STR('X':@FM,99999999)
CRT TIME()
ATTCNT=DCOUNT(ARR,@FM)
FOR ATT=1 TO ATTCNT
ATTVAL=ARR<ATT>
NEXT ATT
CRT TIME()
LOOP
REMOVE ATTVAL FROM ARR SETTING MORE
WHILE ATTVAL:MORE DO
REPEAT
CRT TIME()

Guess what? Jim was/is right! Why are we not surprised?! The
FOR...NEXT loop took 22 secs. The LOOP...REMOVE...REPEAT loop took -
wait for it... 115 secs. So - those of us who have been dilligently
coding for efficiency are actually cutting code that is 5 times slower
than it could/should be.

I figure that deserves a HEADS UP!!!

Cheers,
Mike.

Jim Idle

unread,
Feb 16, 2007, 10:53:31 AM2/16/07
to jB...@googlegroups.com
-----Original Message-----
From: jB...@googlegroups.com [mailto:jB...@googlegroups.com] On Behalf Of
mic...@preece.net

> Guess what? Jim was/is right! Why are we not surprised?! The
> FOR...NEXT loop took 22 secs. The LOOP...REMOVE...REPEAT loop took -
> wait for it... 115 secs. So - those of us who have been dilligently
> coding for efficiency are actually cutting code that is 5 times slower
> than it could/should be.
>
> I figure that deserves a HEADS UP!!!

Yes - once in a while such things should be reposted. It is for this reason
that John Lambert and I wanted to start a wiki site for jBASE. However, as
the only contributions were from ourselves and one guy asking a questions,
there did not seem much point continuing it ;-). Perhaps we should maintain
some kind of FAQ instead though.

Jim

CLIF

unread,
Feb 16, 2007, 11:01:31 AM2/16/07
to jBASE
There is 2 ways to look at this. The first is to think Jim made some
improvements and the second is think Jim broke something in the REMOVE
statement. I'm sure Jim wants you to believe the former.

On Feb 16, 3:42 am, mich...@preece.net wrote:
> When I first started cutting code to process data in a dynamic array I
> would always do it this way:
>
> ATTCNT=DCOUNT(MY.ARRAY,AM)
> FOR ATT=1 TO ATTCNT
> ATTVAL=MY.ARRAY<ATT>
> (do something)
> NEXT ATT
>
> Then, when I did my first contract at a Pr1me Information site, I was
> told it was much more efficient to do it this way instead:
>
> LOOP
> REMOVE ATTVAL FROM MY.ARRAY SETTING MORE
> WHILE ATTVAL:MORE # "" DO
> (something)
> REPEAT
>
> As with a lot of things, I felt more comfortable doing things the
> 'old' way but, sure enough, tests proved that the
> LOOP...REMOVE...REPEAT construct was indeed more efficient.
>
> In the course of googling back over previous posts in here I noticed,

> in this threadhttp://tinyurl.com/2jyr9ethat Jim said that, because

Daniel Klein

unread,
Feb 16, 2007, 11:15:36 AM2/16/07
to jB...@googlegroups.com
On 2/16/07, Jim Idle <ji...@temporal-wave.com> wrote:

It is for this reason
that John Lambert and I wanted to start a wiki site for jBASE.

Just curious, Jim, what were you planning on using for the wiki engine?

Dan

Jim Idle

unread,
Feb 16, 2007, 11:34:52 AM2/16/07
to jB...@googlegroups.com

-----Original Message-----
From: jB...@googlegroups.com [mailto:jB...@googlegroups.com] On Behalf Of

CLIF
Sent: Friday, February 16, 2007 8:02 AM
To: jBASE
Subject: Re: Remove the remove


> There is 2 ways to look at this.

I think that you mean "There are...", but in fact there are 3 ways to look
at this.

> The first is to think Jim made some
> improvements and the second is think Jim broke something in the REMOVE
> statement. I'm sure Jim wants you to believe the former.

You need to know a lot more about the way this stuff works internally before
suggesting #2 ;-)

The third way is the correct way and that is that PRIME added a stupid
REMOVE concept because they could not or did not think about optimizing
their dynamic array access. Then they propagated it to everyone as a
"performance improvement" while avoiding any questions about why the normal
access was slow in the first place. Then the rest of us are stuck with it.
REMOVE MUST behave like REMOVE, and this limits the optimizations that can
be done to it as it is a poor man's optimization.

The easiest way to "fix" this would be to take out the dynamic array
optimizations in jBASE, in which case REMOVE would indeed be faster than a
loop :-)

Jim

Jim Idle

unread,
Feb 16, 2007, 11:35:22 AM2/16/07
to jB...@googlegroups.com

A wiki.

 

Jim

 

From: jB...@googlegroups.com [mailto:jB...@googlegroups.com] On Behalf Of Daniel Klein
Sent: Friday, February 16, 2007 8:16 AM
To: jB...@googlegroups.com
Subject: Re: Remove the remove

 

On 2/16/07, Jim Idle <ji...@temporal-wave.com> wrote:

CLIF

unread,
Feb 16, 2007, 11:51:23 AM2/16/07
to jBASE
Just a little friendly humor and your right its there are not there
is. Still trying to wake up this morning.

On Feb 16, 3:42 am, mich...@preece.net wrote:

> When I first started cutting code to process data in a dynamic array I
> would always do it this way:
>
> ATTCNT=DCOUNT(MY.ARRAY,AM)
> FOR ATT=1 TO ATTCNT
> ATTVAL=MY.ARRAY<ATT>
> (do something)
> NEXT ATT
>
> Then, when I did my first contract at a Pr1me Information site, I was
> told it was much more efficient to do it this way instead:
>
> LOOP
> REMOVE ATTVAL FROM MY.ARRAY SETTING MORE
> WHILE ATTVAL:MORE # "" DO
> (something)
> REPEAT
>
> As with a lot of things, I felt more comfortable doing things the
> 'old' way but, sure enough, tests proved that the
> LOOP...REMOVE...REPEAT construct was indeed more efficient.
>
> In the course of googling back over previous posts in here I noticed,

> in this threadhttp://tinyurl.com/2jyr9ethat Jim said that, because

M. MARTIN Thierry

unread,
Feb 17, 2007, 4:05:38 PM2/17/07
to jBASE
I test on Universe and the result is same. I add a test with the
READNEXT with the syntax for Pick flavor :
SELECT ARR TO BRR
LOOP
READNEXT ATTVAL FROM BRR ELSE
EXIT
END
REPEAT
CRT TIME()
For 9999999 field the result is 10s in FOR/NEXT, 25s in REMOVE and 14s
in READNEXT.

Thierry.

On Feb 16, 12:42 pm, mich...@preece.net wrote:
> When I first started cutting code to process data in a dynamic array I

> would always do it this way:(...)

mic...@preece.net

unread,
Feb 18, 2007, 7:56:29 PM2/18/07
to jBASE

On Feb 17, 9:05 pm, "M. MARTIN Thierry" <goo...@martin-thierry.nom.fr>
wrote:


> I test on Universe and the result is same. I add a test with the
> READNEXT with the syntax for Pick flavor :
> SELECT ARR TO BRR
> LOOP
> READNEXT ATTVAL FROM BRR ELSE
> EXIT
> END
> REPEAT
> CRT TIME()
> For 9999999 field the result is 10s in FOR/NEXT, 25s in REMOVE and 14s
> in READNEXT.
>
> Thierry.
>

I saw some code the other day like this (I'm sure many of you will
have seen something like it too)...

LOOP
MYVAL=ARR<1>
DEL ARR<1>
WHILE MYVAL#"" DO
REPEAT

I tried getting timings on this but gave up. It took WAY too long.

Mike.

Jim Idle

unread,
Feb 20, 2007, 12:57:06 PM2/20/07
to jB...@googlegroups.com
Try

CHANGE @AM:@AM TO @AM IN ARR

You might need to experiment a bit as I can't remember if this will
successfully change @AM:@AM:@AM to just @AM (also watch for first element
being "" and so on, but you get the picture.)

Jim

-----Original Message-----
From: jB...@googlegroups.com [mailto:jB...@googlegroups.com] On Behalf Of
mic...@preece.net
Sent: Sunday, February 18, 2007 4:56 PM
To: jBASE
Subject: Re: Remove the remove

Reply all
Reply to author
Forward
0 new messages