Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming.threads > #969
| From | Melzzzzz <mel@zzzzz.com> |
|---|---|
| Newsgroups | comp.lang.c++, comp.programming.threads |
| Subject | Re: Why is java consumer/producer so much faster than C++ |
| Date | 2012-07-23 15:33 +0200 |
| Organization | albasani.net |
| Message-ID | <jujjqr$b3o$1@news.albasani.net> (permalink) |
| References | <juht3o$a3a$1@news.albasani.net> <juiret$jqb$1@speranza.aioe.org> <juj99h$ges$2@news.albasani.net> <jujdit$uv9$1@speranza.aioe.org> |
Cross-posted to 2 groups.
On Mon, 23 Jul 2012 11:46:37 +0000 (UTC) Juha Nieminen <nospam@thanks.invalid> wrote: > In comp.lang.c++ Melzzzzz <mel@zzzzz.com> wrote: > > I think that pressure on condition variable is greater with non > > dynamic allocation, therefore it is slower. > > That sentence doesn't make any kind of sense. I has sense in this context. I will provide example. > > > I don't think it's > >> physically possible for 'new int' to be faster than using ints by > >> value under any possible circumstance, even if we assumed a highly > >> optimized version of 'new' that does magic under the hood to be 10 > >> times faster than the regular 'new'. > > > > That's because new is very fast and don;t take much time of program > > in this example. > > 'new' is a very slow operation in C++, and even if it weren't, it just > can't be faster than using an integer by value. It's physically > impossible. (The pointer that points to the allocated int is also an > integral value at the low level, so by allocating something > dynamically you are only adding to the amount of values being > handled, and the overall complexity of the program.) Yes, but overall complexity can be masked with something else like in this case. > > Can you give any scenario where handling pointers would be faster than > handling ints? This scenario is exactly example. My queue is limited to capacity nodes. When capacity is reached, producer waits on condition variable until it is emptied. In first example queue was 100000 nodes so slow down with plain ints isn't just that noticabe. But if I put just 1000 nodes here is what happens: (dynamic ints , unique_ptr, random function and array assignement) bmaxa@maxa:~/examples$ time ./consprod real 0m23.523s user 0m32.390s sys 0m10.581s but look at this: (no dynamic ints, no random function, no assignment) : bmaxa@maxa:~/examples$ time ./consprod1 real 0m35.654s user 0m30.882s sys 0m34.202s it's more than 10 seconds slower! just ints! > > >> 'new' is slow, especially when compared to java's. > > > > In this example new takes very little time. > > You are executing tens of thousands of 'new's. That is slow. It is slow but waiting on condition is much slower so, faster producer increases number of times condition waits, so actually that makes program slower...
Back to comp.programming.threads | Previous | Next — Previous in thread | Next in thread | Find similar
Why is java consumer/producer so much faster than C++ Melzzzzz <mel@zzzzz.com> - 2012-07-22 23:59 +0200
Re: Why is java consumer/producer so much faster than C++ Joshua Maurice <joshuamaurice@gmail.com> - 2012-07-22 15:42 -0700
Re: Why is java consumer/producer so much faster than C++ Melzzzzz <mel@zzzzz.com> - 2012-07-23 01:28 +0200
Re: Why is java consumer/producer so much faster than C++ Luca Risolia <luca.risolia@studio.unibo.it> - 2012-07-23 02:03 +0200
Re: Why is java consumer/producer so much faster than C++ Melzzzzz <mel@zzzzz.com> - 2012-07-23 12:17 +0200
Re: Why is java consumer/producer so much faster than C++ Luca Risolia <luca.risolia@studio.unibo.it> - 2012-07-24 00:33 +0200
Re: Why is java consumer/producer so much faster than C++ Juha Nieminen <nospam@thanks.invalid> - 2012-07-23 06:37 +0000
Re: Why is java consumer/producer so much faster than C++ Melzzzzz <mel@zzzzz.com> - 2012-07-23 12:33 +0200
Re: Why is java consumer/producer so much faster than C++ Juha Nieminen <nospam@thanks.invalid> - 2012-07-23 11:46 +0000
Re: Why is java consumer/producer so much faster than C++ Melzzzzz <mel@zzzzz.com> - 2012-07-23 15:33 +0200
Re: Why is java consumer/producer so much faster than C++ Dombo <dombo@disposable.invalid> - 2012-07-23 22:57 +0200
Re: Why is java consumer/producer so much faster than C++ Joshua Maurice <joshuamaurice@gmail.com> - 2012-07-23 21:54 -0700
Re: Why is java consumer/producer so much faster than C++ Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-07-24 12:50 +0000
Re: Why is java consumer/producer so much faster than C++ Ricardo Nabinger Sanchez <rnsanchez@wait4.org> - 2012-08-14 22:48 +0000
csiph-web