Page 1 of 1

Where

Posted: Fri Aug 07, 2009 2:21 pm
by ConvertFromOldNGs
by Torrie Moore >> Thu, 3 Feb 2000 3:48:08 GMT

Does anyone know which version of the following code is more efficient. We are finding the second generally takes less time and wondered if if resulted in faster code when compiling.

Torrie

1) foreach obj in collection where condition do
endforeach;

2) foreach obj in collection do
if condition then
endif;
endforeach;

Re: Where

Posted: Fri Aug 07, 2009 2:21 pm
by ConvertFromOldNGs
by Allistar Melville >> Thu, 3 Feb 2000 7:24:39 GMT

I always thought that the first was faster if the where condition is based on a key of the dictionary you are traversing.

I.e. if you have a class called Supplier with a dictionary keyed by Supplier.name then this foreach:

foreach supplier in allSuppliers where (supplier.name > "Bob") do
//..
endforeach;

would be optimised because you wouldn't be pulling all objects down to the client (correct me if I'm wrong anyone)...

Allistar.

------------------------------------------------------------------
Allistar Melville
Software Developer
Auckland, NEW ZEALAND

Greentree International,
Developer of Greentree Financial Software. ------------------------------------------------------------------