[Adium-devl] HOM
Ofri Wolfus
ofri.wolfus at gmail.com
Sat Nov 11 14:28:18 UTC 2006
First of all, unit (and speed) tests are included with the source so
anyone can see the results on their own machine. On my eMac with 1.25
GHz G4, 768MB RAM and 10.4.7 the results of this example with an
array of 3 objects are (each test was performed 1000 times and the
results are the average times):
NSEnumerator: 0.000010 sec
-objectAtIndex: 0.000005 sec
-selectWhere: 0.000013 sec
-selectWhere: with a cached Message instance: 0.000005 sec
For large arrays (with 10000 strings) the results are:
NSEnumerator: 0.005581 sec
-objectAtIndex: 0.006068 sec
-selectWhere: 0.007683 sec
-selectWhere: with a cached Message instance: 0.007740 sec
With that being said, I the differences between the iterations vary
based on the iteration method (e.g. -selectWhere: vs -rejectWhere:)
and the collection being used. I think I can safely say that for
really large collections HOM is a bit faster, but for small
collections it's a bit slower. Anyhow, I think these slight
differences in speed are not something that'll be noticeable.
- Ofri
- - - - - - - - - - - - - - - - - - -
http://www.dpompa.com
- - - - - - - - - - - - - - - - - - -
On 11/11/2006, at 15:57, Colin Barrett wrote:
> I've heard some rumblings from David about good performance, but can
> you give us an idea of how say, the initial example:
>
> NSEnumerator *e = [someCollection objectEnumerator];
> NSString *str;
> NSMutableArray *r = [NSMutableArray array];
> while ((str = [e nextObject]))
> if ([str hasPrefix:@"a"])
> [r addObject:str];
>
> compares to:
>
> NSMutableArray *r = [someCollection selectWhere:MSG(hasPrefix:@"a"),
> nil];
>
> in terms of performance?
>
> -Colin
>
> On Nov 11, 2006, at 3:18 AM, Ofri Wolfus wrote:
>
>> Hi guys,
>>
>> As some of you may know, I've been working on a higher order
>> messaging (HOM) implementation[1] for some time now, and I'd like to
>> suggest it for Adium. For those of you who are not familiar with the
>> HOM concept, it's basically a way to pass messages as arguments to
>> other messages (see http://www.metaobject.com/papers/
>> Higher_Order_Messaging_OOPSLA_2005.pdf
>> for the OOPSLA paper about HOM). In practice, probably the most
>> common usage pattern for HOM is in iterations over collections.
>> Instead of writing:
>> NSEnumerator *e = [someCollection objectEnumerator];
>> NSString *str;
>> NSMutableArray *r = [NSMutableArray array];
>> while ((str = [e nextObject]))
>> if ([str hasPrefix:@"a"])
>> [r addObject:str];
>>
>> you'd just do NSMutableArray *r = [someCollection selectWhere:MSG
>> (hasPrefix:@"a"), nil]; where -selectWhere: is a method that accepts
>> variable number of messages, sends them by order to each member of
>> the collection, and returns the objects that returned YES for the
>> last message. Another example for it will be NSArray
>> *availableContacts = [contacts selectWhere:MSG(status), MSG
>> (isEqualToString:@"Available"), nil];.
>> As you might have guessed, MSG() is a macro that returns an
>> autoreleased Message instance ("Message" is the class's name) which
>> can then be passed around like any other object.
>>
>> In my experience, using HOM can greatly simplify code in some common
>> cases, which I think will do only good to Adium's huge code-base.
>>
>> What do you think?
>> - Ofri
>>
>> - - - - - - - - - - - - - - - - - - -
>> http://www.dpompa.com
>> - - - - - - - - - - - - - - - - - - -
>>
>> [1] http://www.dpompa.com/?page_id=4
>>
>> _______________________________________________
>> Adium-devl mailing list
>> Adium-devl at adiumx.com
>> http://adiumx.com/mailman/listinfo/adium-devl_adiumx.com
>
>
> _______________________________________________
> Adium-devl mailing list
> Adium-devl at adiumx.com
> http://adiumx.com/mailman/listinfo/adium-devl_adiumx.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://adium.im/pipermail/devel_adium.im/attachments/20061111/ba7a5b70/attachment-0001.html>
More information about the devel
mailing list