50\% of my simulation time is spent on the following code:
internal double simWithdrawalFast(double t)
{
simarrivals.Enqueue(t + Leadtime);
return simarrivals.Dequeue();
}
where simarrivals is a System.Collection.Generic.Queue<double>.
If I write my own queue, will it be faster?
EDIT: note that there are doubles in the queue to begin with, i.e. the queue has about 200 elements when simwithdrawal is called. Each call adds and removes an element.
The implementations of these two methods seem pretty minimalist to me:
I have a hard time believing the semantics of a queue can be honored by code much more efficient than this. Therefore, your problem is probably at a higher level. Why is this method (
simWithdrawalFast) getting called so much? You’re probably going to have to find a way to make your overall algorithm more efficient rather than finding a more efficient data structure.If the problem is frequent resizing of the queue, you might be able to improve the performance somewhat by specifying a
capacitywhen constructing the queue. My hunch though is that this isn’t your problem.