Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming.threads > #965
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Newsgroups | comp.lang.c++, comp.programming.threads |
| Subject | Re: Why is java consumer/producer so much faster than C++ |
| Date | 2012-07-23 06:37 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <juiret$jqb$1@speranza.aioe.org> (permalink) |
| References | <juht3o$a3a$1@news.albasani.net> |
Cross-posted to 2 groups.
In comp.lang.c++ Melzzzzz <mel@zzzzz.com> wrote: > I even tried c++ without dynamic > memory management (except queue itself) and that is *even slower*. If two C++ programs are otherwise identical, except that one uses 'new int' and the other just uses the ints by value, and the former is faster than the latter, then there's something horribly wrong in the way you are measuring, or something else. 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'. > std::unique_lock<std::mutex> lock(m_); > produced.put(std::unique_ptr<int>(new int(i))); > arr[std::rand()%size] = produced.take(); I don't know what's the cause of the slowness in your program, but I quoted above the three possible culprits I would first investigate (which happen to be in order of likeliness). Locks are slow. They are probably slower than 'new'. 'new' is slow, especially when compared to java's. std::rand() is slow, although probably does not account for that much slowness, but could be a minor contributing factor.
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