procmail
[Top] [All Lists]

Re: efficiency question

2002-04-23 13:54:20
At 15:06 2002-04-23 -0400, Matt Garretson did say:
:0
* 0^1 condition A
* 0^1 condition B
* 0^1 condition C

Hmm, weird score you have there.

:0
* (condition A|condition B|condition C)
{ fancy actions }

since it probably only scans the message once (?)

Think again -- when it doesn't find A, it looks for B, and when it doesn't find B, it looks for C. How exactly do you figure that this differs from:

:0
* condition A
{ action A }

...

:0
* condition C
{ action C }

Certainly, from some expressions, it might make sense to do an or condition, but if you have *DIFFERENT* actions, how much more processing are you going to expend figuring out which action to take, since you obviously have to do further expressions to achieve that? Is it any more comprehensible for doing so?

If you want to optimize, you'd put the most frequently occurring condition first. Next to that, you'd put the least intensive conditions before more intensive ones (things that check specific headers vs. things that scan the whole body for instance), where two separate conditions might produce the same action.

When you have a common action, you can either combine conditions (using maximal scoring):

:0
* 9876543210^0 condition A
* 9876543210^0 condition C
{ action }

Or set a flag through a chained else, THEN take action:

:0
* condition A
{ set flag }

:0E
* condition B
{ set flag }

...

:0E
* condition n
{ set flag}

:0
* FLAG ?? value
{ action )

:0
* FLAG ?? othervalue
{ action }

etc.

---
 Sean B. Straw / Professional Software Engineering

 Procmail disclaimer: <http://www.professional.org/procmail/disclaimer.html>
 Please DO NOT carbon me on list replies.  I'll get my copy from the list.

_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>