Friday 26 August 2011

Performance of collection types compared

Question:
Is referencing a varray of 20 elements faster than referencing an associative array of 20 elements?
Answer:
Sure, I could be lazy and just tell you: "You will not see any appreciable difference between the various collection types. Take your pick!" But among other reasons to not do that, I could be wrong! So I built a script to compare the performance of assignments to the various collection types, varying the size of the collections (that is, how many rows are defined in each). The results surprised me a bit.
I ran the following test in Oracle Database 10g 10.1.0.2. When executing my test loops 100,000 times each, I found that:
• When populating collections with just 20 rows of data, associative arrays performed slightly slower than nested tables and varrays.
• At 50 rows of data, performance was virtually the same.
• At 100 and 1,000 rows of data, associative arrays consistently outperformed both nested tables and varrays, but by less than 10 percent.
When I executed the 20,row test over 1 million iterations, the associative array assignment was slightly faster.
Considering the number of iterations I ran for these tests and the delta in performance, I conclude that most programmers should not decide on the collection type they use within PL/SQL code based on performance. Rather, you should see if any of the unique characteristics of each of the types offer clear advantages.
Click here to view the script and the full table of results (in a comment at the bottom of the file). You can run this sript yourself after installing the tmr object type defined on the Downloads page.

No comments:

Post a Comment