Selected Line Only

Rob Mostyn mostyn at platformis.net
Wed Jul 13 16:54:41 UTC 2022


Ok folks…  I have done some benchmarking on the $Loop v. For list.$line

I have excluded
	Set current list
	For each line in list (selected lines only)

from consideration because that is “so Omnis Classic” and one cannot kist loop within another list loop.

If you want to loop “selected lines only” then $Loop is much faster than testing each line’s $selected, though to be fair, I don’t think a user would experience much difference.
	20,000 rows concatenating two string
	For…	41 ticks
	$Loop	23 ticks
	difference = -0.3 seconds		$Loop 78% faster

If you want to loop through the whole list then For list.$line…
is consistently (but not always) faster.

Highlights processing 20,000 rows:

incrementing a number (no real burden within the loop)
	For…  5 ticks
	$Loop  84 ticks
	difference = 1.3 seconds		$Loop 94% slower

searching through a list
	For…	125 ticks
	$Loop	210 ticks
	difference = 1.4 seconds		$Loop 40% slower (2.1s v. 3.5s)

concatenating two strings and placing in list
	For…	474 ticks
	$Loop	481 ticks
	difference = 0.1 seconds		$Loop 1% slower

fetching a record from db (on same machine as Omnis)
	For…	6590 ticks
	$Loop	6834 ticks
	difference = 4.1 seconds		$Loop 4% slower

I cannot claim the $Loop method as my own but I liked the look of it when I first came across it.  I find it easier to read the code. Its less typing.  test for selected is a doddle but that is infrequent for me.

So I am sticking with it!   :-)
Rob

> On 12 Jul 2022, at 06:40, Rocco [KUNVI] <r.ventura at kunvi.it> wrote:
> 
> Hi to $All
> 
> I use the while circle…
> 
> Do List1.$first(1)
> While List1.line
> 
>   Do …
> 
>  Do List1.$next(0,1)
> End while
> 
> Bye
> 
> Rocco
> 
> Il giorno lun 11 lug 2022 alle 17:05 Rudolf Bargholz <rudolf at bargholz.ch>
> ha scritto:
> 
>> Hi Rob,
>> 
>> I did my tests more than 10 years ago and have no idea where they are now
>> as well 😊 As soon as I sent the mail I thought this would come up.
>> 
>> Regards
>> 
>> Rudolf Bargholz
>> 
>> -----Ursprüngliche Nachricht-----
>> Von: omnisdev-en <omnisdev-en-bounces at lists.omnis-dev.com> Im Auftrag von
>> Rob Mostyn
>> Gesendet: Montag, 11. Juli 2022 15:55
>> An: OmnisDev List - English <omnisdev-en at lists.omnis-dev.com>
>> Betreff: Re: Selected Line Only
>> 
>> We did the benchmark about 5 years ago Rudolf.
>> I probably recorded the results somewhere but I wouldn’t know where to
>> look for it now.
>> 
>> The “empty loop” involved a list of 10,000 rows (it might have been 100k)
>> I think and the loop simply had calculate inInteger as inInteger+1
>> 
>> The difference between the For loop and $Loop() was significant.  $Loop
>> was much slower but the whole iteration took about 10 or 20 seconds or
>> something.  $Loop looked b-a-d .  I don’t remember the actual figures.
>> 
>> But as soon as I put some work in the loop (more than incrementing an
>> integer) everything changed.
>> 
>> I see I am going to have to re-create this benchmark now!   :-)
>> 
>> I’ll get back to you  in a few days.
>> Rob
>> 
>> 
>>> On 11 Jul 2022, at 14:51, Rudolf Bargholz <rudolf at bargholz.ch> wrote:
>>> 
>>> Hi Rob,
>>> 
>>> Have you tested using a normal FOR loop compared to using $fist()and
>> $next(). I did a comparison many years ago in our Studio 4.3, and the FOR
>> loop was a faster than the $first() and $next(). I actually found that "For
>> each line in list" with a "Set current list" was the fastest option when
>> looping. It is ugly to look at, from my perspective now, but I do use this
>> old structure when I must eek out the last bit of performance from Omnis
>> Studio.
>>> 
>>> Regards
>>> 
>>> Rudolf Bargholz
>>> 
>>> -----Ursprüngliche Nachricht-----
>>> Von: omnisdev-en <omnisdev-en-bounces at lists.omnis-dev.com> Im Auftrag
>>> von Rob Mostyn
>>> Gesendet: Montag, 11. Juli 2022 12:46
>>> An: OmnisDev List - English <omnisdev-en at lists.omnis-dev.com>
>>> Betreff: Re: Selected Line Only
>>> 
>>> We have done some benchmarking on this and the simple conclusion is this:
>>> 
>>> If you have nothing happening in the loop then the CPU used to process
>> $Loop() is more expensive than using For loop.
>>> 
>>> But I have never written a loop that does nothing inside it, so this is
>> a rather silly indicator of performance.
>>> 
>>> As soon as you put work inside the loop then its the work being done
>> that determines the CPU used and the overhead of $Loop() is negligible.
>> Really... next to nothing!  The difference processing 500,000 records would
>> be something like 500 seconds compared to less than 501 seconds.  Your
>> users will not notice it.
>>> 
>>> Advantages for me:
>>> a.    The code is much easier to read.
>>> b.    There are fewer keystrokes to define the loop.
>>> c.    Looping through selected lines only is very easy with fewer
>> keystrokes still
>>> 
>>> Rob
>>> 
>>>> On 11 Jul 2022, at 11:18, Martin Obongita via omnisdev-en <
>> omnisdev-en at lists.omnis-dev.com> wrote:
>>>> 
>>>> Hi Rob,
>>>> Won't the while$loop be slower than a FOR loop, assuming you have
>> 500,000 transactions?
>>>> Martin.
>>>>  On Monday, July 11, 2022 at 11:46:36 AM GMT+3, Rob Mostyn <
>> mostyn at platformis.net> wrote:
>>>> 
>>>> And here is another take on this issue:
>>>> 
>>>> We have a method/function in our startup_task (and copied into the
>> superclass for remote_tasks) called $Loop.
>>>> 
>>>> When running our code you will frequently see this:
>>>> Calculate ilDisplay.$line as 0
>>>> While $Loop(ilDisplay)
>>>>   # do whatever
>>>> End while
>>>> 
>>>> for selected lines only it would look like this:
>>>> When running our code you will frequently see this:
>>>> Calculate ilDisplay.$line as 0
>>>> While $Loop(ilDisplay,kTrue)
>>>>   # do whatever
>>>> End while
>>>> 
>>>> 
>>>> 
>>>> Here is the contents of $Loop:
>>>> param1:  pList (field reference)
>>>> param2: pSelectedOnly (boolean, default kFalse)
>>>> 
>>>> If pList.$line=0
>>>> Do pList.$first(pSelectedOnly)
>>>> Else
>>>> Do pList.$next(pList.[pList.$line],pSelectedOnly)
>>>> End If
>>>> Quit method pList.$line
>>>> 
>>>> 
>>>> Regards,
>>>> Rob
>>>> 
>>>> 
>>>>> On 11 Jul 2022, at 06:45, Rudolf Bargholz <rudolf at bargholz.ch> wrote:
>>>>> 
>>>>> Hi Martin,
>>>>> 
>>>>> Calculate lLineCount as List.$linecount For List.$line from 1 to
>>>>> lLinecount step 1  If List.0.$selected
>>>>>   ... Do stuff on the selected lines  End If Enf For
>>>>> 
>>>>> If you are in an object class, in an instance, then the following can
>> also work:
>>>>> 
>>>>> Do List.$sendall($cinst.$processLine($sendallref),$ref.$selected)
>>>>> 
>>>>> For each selected line the method $processLine is called with the List
>> as a field reference parameter with the appropriate selected line set as
>> current.
>>>>> 
>>>>> Regards
>>>>> 
>>>>> Rudolf Bargholz
>>>>> 
>>>>> -----Ursprüngliche Nachricht-----
>>>>> Von: omnisdev-en <omnisdev-en-bounces at lists.omnis-dev.com> Im
>>>>> Auftrag von Martin Obongita via omnisdev-en
>>>>> Gesendet: Sonntag, 10. Juli 2022 22:21
>>>>> An: omnisdev-en at lists.omnis-dev.com
>>>>> Cc: Martin Obongita <martin.obongita at yahoo.com>
>>>>> Betreff: Selected Line Only
>>>>> 
>>>>> Hi Friends, What is the syntax for "Selected lines only" in the FOR
>> loop statement, For each line in list from 1 to iDataList step 1?
>>>>> 
>>>>> _____________________________________________________________
>>>>> Manage your list subscriptions at https://lists.omnis-dev.com Start
>>>>> a new message -> mailto:omnisdev-en at lists.omnis-dev.com
>>>>> _____________________________________________________________
>>>>> Manage your list subscriptions at https://lists.omnis-dev.com Start
>>>>> a new message -> mailto:omnisdev-en at lists.omnis-dev.com
>>>> 
>>>> _____________________________________________________________
>>>> Manage your list subscriptions at https://lists.omnis-dev.com Start a
>>>> new message -> mailto:omnisdev-en at lists.omnis-dev.com
>>>> 
>>>> _____________________________________________________________
>>>> Manage your list subscriptions at https://lists.omnis-dev.com Start a
>>>> new message -> mailto:omnisdev-en at lists.omnis-dev.com
>>> 
>>> _____________________________________________________________
>>> Manage your list subscriptions at https://lists.omnis-dev.com Start a
>>> new message -> mailto:omnisdev-en at lists.omnis-dev.com
>> 
>> _____________________________________________________________
>> Manage your list subscriptions at https://lists.omnis-dev.com
>> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com
>> 
> --
> 
> _________________________________
> 
> Distinti saluti. Best regards.
> 
> 
> 
> *Rocco Dr. Ventura*
> 
> WMS Analist and Software Developer
> 
> 
> 
> *KUNVI srl - **Experiences Holding *(G)* - www.kunvi.it
> <http://www.kunvi.it>*
> 
> Email: r.ventura at kunvi.it - Mobile: +39 348 5186051
> _____________________________________________________________
> Manage your list subscriptions at https://lists.omnis-dev.com
> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com



More information about the omnisdev-en mailing list