Where

Forums for specific tips, techniques and example code
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Where

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:21 pm

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;

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Where

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:21 pm

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. ------------------------------------------------------------------


Return to “Tips and Techniques”

Who is online

Users browsing this forum: No registered users and 8 guests