0

What I've observed is, std::queue .push takes longer as the queue size goes on increasing. Is it normal behavior or I am doing wrong something?

I want the time to be consistent regardless of number of elements the container has. What are better alternatives to std::queue?

Atul
  • 3,778
  • 5
  • 47
  • 87
  • 2
    Default container? It should be constant: http://www.cplusplus.com/reference/deque/deque/push_back/ – Marco A. Oct 29 '14 at 12:40
  • What specialization of std::queue do you use? – Jan Hudec Oct 29 '14 at 12:42
  • 2
    Maybe relevant: [discussion of complexity of deque::push_back](http://stackoverflow.com/questions/8335430/complexity-requirements-for-stddequepush-back-front) – M.M Oct 29 '14 at 12:43
  • You could use `list` to guarantee O(1) push, although this may be worse than deque in real performance time and memory usage – M.M Oct 29 '14 at 12:44
  • Thanks! I guess I need to revisit the code. I use `push` at multiple places and within thread sync locks. So suspected `push` operation. But now I feel problem is somewhere else. – Atul Oct 29 '14 at 12:46

0 Answers0