cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
325
Views
5
Helpful
2
Replies

Message filter with several conditions

Steflstefan
Level 1
Level 1

Hello @All,

Are several conditions checked equally one after the other or do the conditions have to be nested by use of " else "?
So variant 1 or 2?

Variant 1

if (recv-listener == "in") {
 if (sendergroup == "TRUSTLIST") {
  action;
 }
 if (sendergroup == "GOODSENDERSLIST") {
  action;
 }
 if (sendergroup == "LOWERREPUTAIONLIST") {
  action;
 }
}


Variant 2

if (recv-listener == "in") {
 if (sendergroup == "TRUSTLIST") {
  action;
 } else {
  if (sendergroup == "GOODSENDERSLIST") {
   action;
  } else {
   if (sendergroup == "LOWERREPUTAIONLIST") {
    action;
   }
  }
 }
}

If both variants work, are there any differences in performance?

Regards Stefan

1 Accepted Solution

Accepted Solutions

I can't speak to it specifically, because I didn't write the code, but variant 2 should be more efficient, especially if you put them in prevalence order... e.g., if you expect more Lowreputationlist hits than anything else, you should put it first so you don't do the other checks.
If it hits one early it shouldn't test the others, while variant 1 will test all of them every time.

In the end you may not see a lot of performance difference... it really depends upon load, and how big those lists are.

View solution in original post

2 Replies 2

I can't speak to it specifically, because I didn't write the code, but variant 2 should be more efficient, especially if you put them in prevalence order... e.g., if you expect more Lowreputationlist hits than anything else, you should put it first so you don't do the other checks.
If it hits one early it shouldn't test the others, while variant 1 will test all of them every time.

In the end you may not see a lot of performance difference... it really depends upon load, and how big those lists are.

Steflstefan
Level 1
Level 1

Hi Ken,

thank you much for your answer.
That's a pretty good hint that the condition that applies most often should be at the top.
Best Regards
Stefan