Thanks to a tweet of Scott Wesley (@swesley_perth), I stumbled upon this blog post by Tony Andrews. In that blog Tony lists a few examples of APEX Conditions and concludes that the declarative approach must be the best way of doing it. Although his assumptions and conclusions makes a lot of sense, I wondered whether it was actually true and what the difference in performance would be. So I created a very similar test myself and take a look at the debug output. And here are the results (in microseconds) ...
So from the table above you can safely conclude that Tony's assumptions and conclusions are actually true. Using a declarative condition is on average two to three times faster than one of the other options. And although it are just very small numbers, when you have a lot of conditions and a lot of users hitting the page - it might add up in the end!
When can't use the declarative approach and you have to choose between one of the others, it doesn't really seem to matter ... in this case. But you have to check that in your situation yourself!
Type
|
Statement
|
Run 1 | Run 2 |
---|---|---|---|
Declarative | ...<nothing here>... |
653
|
667
|
PL/SQL Expression | "...Execute Statement: begin wwv_flow.g_boolean := :P3_JOB_ID = 'AD_PRES'; end;” |
1533
|
1823 |
SQL Exists | ...Execute Statement: select count(*) from sys.dual where exists (SELECT NULL FROM DUAL WHERE :P3_JOB_ID = 'AD_PRES') | 1684 | 2023 |
PL/SQL Function | """...Execute Statement: declare function x return boolean is begin begin" return :P3_JOB_ID = 'AD_PRES'; end; " return null; end; begin wwv_flow.g_boolean := x; end;"" | 2537 | 1528 |
So from the table above you can safely conclude that Tony's assumptions and conclusions are actually true. Using a declarative condition is on average two to three times faster than one of the other options. And although it are just very small numbers, when you have a lot of conditions and a lot of users hitting the page - it might add up in the end!
When can't use the declarative approach and you have to choose between one of the others, it doesn't really seem to matter ... in this case. But you have to check that in your situation yourself!
Comments