Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #17321

Re: Why is java consumer/producer so much faster than C++

From James Kanze <james.kanze@gmail.com>
Newsgroups comp.lang.c++
Subject Re: Why is java consumer/producer so much faster than C++
Date 2012-07-29 03:27 -0700
Organization http://groups.google.com
Message-ID <f1fc53b0-2e62-4406-bf0d-e793950266ff@googlegroups.com> (permalink)
References <juht3o$a3a$1@news.albasani.net>

Show all headers | View raw


On Sunday, July 22, 2012 10:59:20 PM UTC+1, Melzzzzz wrote:
> I have played little bit with new C++11 features and compared,

> java performance to c++.

> Actually this was meant to be GC vs RAII memory management,
> but boiled down to speed of BlockingQueue class in java,
> and mine in c++.

> It seems that java implementation is so much more efficient
> but I don't know why. I even tried c++ without dynamic 
> memory management (except queue itself) and that is *even slower*.
> Must be some quirks with a queue ;)

Just a guess (I don't know anything about the Java
BlockingQueue), but your C++ implementation uses an extensible
queue; the restriction on the queue size is external.  From the
code, I'd guess that the Java blocking queue is a fixed length
(established once in the constructor).  This means that once the
queue has been constructed, there are no more allocations in
Java; in C++, I think you'll find that std::deque does allocate
and free new memory as it expands and contracts.

You might try replacing std::deque with a simple, std::vector
based circular buffer.  Construct the std::vector to its fixed
size once at the beginning, and just keep two iterators into it:
one for writing, and one for reading.  Wrap the iterators each
time they reach the end.  (Since the limit conditions for full
and empty are sometimes difficult to implement, you'd be better
off searching an existing implementation on the net.  I'd be
surprised if Boost didn't have one, for example.)

-- 
James

Back to comp.lang.c++ | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

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++ Bo Persson <bop@gmb.dk> - 2012-07-24 19:50 +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++ Zoltan Juhasz <zoltan.juhasz@gmail.com> - 2012-07-23 06:57 -0700
    Re: Why is java consumer/producer so much faster than C++ Melzzzzz <mel@zzzzz.com> - 2012-07-23 18:42 +0200
      Re: Why is java consumer/producer so much faster than C++ Howard Hinnant <howard.hinnant@gmail.com> - 2012-07-23 13:23 -0700
        Re: Why is java consumer/producer so much faster than C++ Melzzzzz <mel@zzzzz.com> - 2012-07-24 00:32 +0200
          Re: Why is java consumer/producer so much faster than C++ Howard Hinnant <howard.hinnant@gmail.com> - 2012-07-23 18:11 -0700
            Re: Why is java consumer/producer so much faster than C++ Melzzzzz <mel@zzzzz.com> - 2012-07-24 11:21 +0200
            Re: Why is java consumer/producer so much faster than C++ Melzzzzz <mel@zzzzz.com> - 2012-07-24 21:45 +0200
              Re: Why is java consumer/producer so much faster than C++ Luca Risolia <luca.risolia@studio.unibo.it> - 2012-07-24 23:24 +0200
                Re: Why is java consumer/producer so much faster than C++ Melzzzzz <mel@zzzzz.com> - 2012-07-25 00:48 +0200
                Re: Why is java consumer/producer so much faster than C++ Luca Risolia <luca.risolia@studio.unibo.it> - 2012-07-25 01:21 +0200
              Re: Why is java consumer/producer so much faster than C++ Howard Hinnant <howard.hinnant@gmail.com> - 2012-07-24 17:35 -0700
              Re: Why is java consumer/producer so much faster than C++ Luca Risolia <luca.risolia@studio.unibo.it> - 2012-07-26 21:19 +0200
                Re: Why is java consumer/producer so much faster than C++ Melzzzzz <mel@zzzzz.com> - 2012-07-26 21:56 +0200
                Re: Why is java consumer/producer so much faster than C++ Luca Risolia <luca.risolia@studio.unibo.it> - 2012-07-26 22:15 +0200
                Re: Why is java consumer/producer so much faster than C++ Melzzzzz <mel@zzzzz.com> - 2012-07-26 23:01 +0200
                Re: Why is java consumer/producer so much faster than C++ Luca Risolia <luca.risolia@studio.unibo.it> - 2012-07-26 23:12 +0200
                Re: Why is java consumer/producer so much faster than C++ Melzzzzz <mel@zzzzz.com> - 2012-07-27 00:24 +0200
                Re: Why is java consumer/producer so much faster than C++ Melzzzzz <mel@zzzzz.com> - 2012-07-27 00:48 +0200
                Re: Why is java consumer/producer so much faster than C++ Melzzzzz <mel@zzzzz.com> - 2012-07-27 05:43 +0200
                Re: Why is java consumer/producer so much faster than C++ Melzzzzz <mel@zzzzz.com> - 2012-07-27 07:43 +0200
                Re: Why is java consumer/producer so much faster than C++ Marc <marc.glisse@gmail.com> - 2012-07-26 21:10 +0000
                Re: Why is java consumer/producer so much faster than C++ Donkey Hottie <donkey@fredriksson.dy.fi> - 2012-07-27 01:05 +0300
                Re: Why is java consumer/producer so much faster than C++ Paavo Helde <myfirstname@osa.pri.ee> - 2012-07-26 17:12 -0500
        Re: Why is java consumer/producer so much faster than C++ yatremblay@bel1lin202.(none) (Yannick Tremblay) - 2012-07-24 12:51 +0000
          Re: Why is java consumer/producer so much faster than C++ Melzzzzz <mel@zzzzz.com> - 2012-07-24 17:47 +0200
            Re: Why is java consumer/producer so much faster than C++ yatremblay@bel1lin202.(none) (Yannick Tremblay) - 2012-07-25 08:09 +0000
              Re: Why is java consumer/producer so much faster than C++ Howard Hinnant <howard.hinnant@gmail.com> - 2012-07-25 08:46 -0700
  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++ James Kanze <james.kanze@gmail.com> - 2012-07-29 03:27 -0700
    Re: Why is java consumer/producer so much faster than C++ Melzzzzz <mel@zzzzz.com> - 2012-07-29 14:40 +0200
  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