Monitoring Splunk

In SPL, which one has better performance when used in search queries: "case" or "if"?

gokadroid
Motivator

Hello

In SPL which one has better performance when used in search queries: "case" or "if" ?

0 Karma
1 Solution

awmorris
Path Finder

They appear virtually identical to me. I just ran both searches on my system (one using CASE and one using IF) and it has a difference of 0.28 seconds searching 1M rows.

index=fictionaldata PRODUCT=VPN| eval locality=case(COUNTRY_NAME == "United States", "Domestic")
This search has completed and has returned 89,399 results by scanning 1,174,774 events in 23.069 seconds

index=fictionaldata PRODUCT=VPN| eval locality=if(COUNTRY_NAME == "United States", "Domestic","Nondomestic")
This search has completed and has returned 89,399 results by scanning 1,174,774 events in 23.35 seconds

View solution in original post

somesoni2
SplunkTrust
SplunkTrust

I don't believe using one over other gives any performance boost. The case is used more for SPL readability.

skoelpin
SplunkTrust
SplunkTrust

I think they are both very close in terms of performance. One thing I would suggest though is to use your highest match case first followed by the next highest all the way to the lowest being last.. This will boost performance because it will search the most frequent case first and prevent the need from having to iterate through more cases to find the match

cmerriman
Super Champion

case is for multiple arguements whereas if for three.

eval field=if(x=1,y,z) >>> if x is 1, then y, otherwise z

eval field=case(x=1,y,x=2,z,1=1,"other") >> if x is 1, then y, if x is 2, then z, if x is anything other 1 or 2, then "other"

the performance of them if they have the same x,y,z argument, is probably the same, but they were created for different reasons.

http://docs.splunk.com/Documentation/Splunk/6.5.0/SearchReference/CommonEvalFunctions

awmorris
Path Finder

They appear virtually identical to me. I just ran both searches on my system (one using CASE and one using IF) and it has a difference of 0.28 seconds searching 1M rows.

index=fictionaldata PRODUCT=VPN| eval locality=case(COUNTRY_NAME == "United States", "Domestic")
This search has completed and has returned 89,399 results by scanning 1,174,774 events in 23.069 seconds

index=fictionaldata PRODUCT=VPN| eval locality=if(COUNTRY_NAME == "United States", "Domestic","Nondomestic")
This search has completed and has returned 89,399 results by scanning 1,174,774 events in 23.35 seconds

Get Updates on the Splunk Community!

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...