Perhaps this is because the interpolation implementation classes perform binary search to locate the position of every x argument. If you call it thousands of times there will be thousands binary searches. In my applications I use interpolation objects as temporal constructs to calculate all the required values once and store them in a container with a more efficient access.
Also, I’d like to take this opportunity to point out that there is a potential danger in the design of interpolation objects – they take iterators as input during construction. This is an additional argument in favor of use of interpolation object as a temporal one. Hope this helps.
Cheers,
Slava Mazur
From: Christopher Targett-Adams [mailto:[hidden email]]
Sent: Sunday, July 31, 2011 5:05 PM
To: [hidden email]
Subject: [Quantlib-users] Performance question
Dear Quantlib users/developers,
I have a question related to the performance of some of the QL classes. I am currently looking at developing a system using the QL framework and have been doing some feasibility studies using some of the yield curve and interpolation classes. I set the following test up:
1) I performed 130000 linear interpolations using the InterpolatedCurve<Linear> class. Basically, I define an x and y std::vector<double> which are 13 elements long and then I have a for loop which performs 130000 iterations and calls the relevant interpolation method on each iteration. It's very simple.
2) I then compare this to a classic procedural implementation of linear interpolation, ie a function that just takes in two double[13] arrays, does a bisection search and then does a linear interpolation between the located grid points. Again, very simple stuff.
I am by no means trying to claim I'm comparing like with like and I expect QL to be a bit slower than procedural c++, however, the QL interpolation is very slow: the 130000 interpolations takes about 4 seconds compared to 0.4 seconds for the procedural implementation.That's 100 times slower! What's more perplexing is even when I take out the error checking and hack the locate method so that it just returns 0 (thus elimating any time spent in the grid seach) it still takes the same order of magnitude to run. There's a lot going on in the code with smart pointer use, std::vectors, iterators, templates, inheritance, polymorphism and my under-the-bonnet knowledge of c++ isn't good enough to allow me to understand why it's taking so long.
Does anyone know what the cause of the poor performance is?
Chris
| Free forum by Nabble | Edit this page |