473,385 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Do you use a garbage collector?

I followed a link to James Kanze's web site in another thread and was
surprised to read this comment by a link to a GC:

"I can't imagine writing C++ without it"

How many of you c.l.c++'ers use one, and in what percentage of your
projects is one used? I have never used one in personal or professional
C++ programming. Am I a holdover to days gone by?
Apr 10 '08
350 11411
"Razii" <DO*************@hotmail.comwrote in message
news:s7********************************@4ax.com...
On Tue, 15 Apr 2008 15:56:40 -0700, "Chris Thomasson"
<cr*****@comcast.netwrote:
>>___________________________________________
java: Test 22 / Time: 2375 ms
vcpp: Test 22 / Time: 1468 ms
-------------------------------------------
java: Test 23 / Time: 3594 ms
vcpp: Test 23 / Time: 2362 ms
-------------------------------------------
java: Test 24 / Time: 33141 ms
vcpp: Test 24 / Time: 9390 ms
-------------------------------------------
java: Test 25 / CRTL-C <took longer than 1 min>
vcpp: Test 25 / Time: 26390 ms
-------------------------------------------
java: Test 26 / CRTL-C <took longer than 1 mins>
vcpp: Test 26 / CRTL-C <took longer than 1 mins>

http://pastebin.com/m45f642a5 (c++) Is that the right one?
Yup.

http://pastebin.com/f3f559ae2 (java)

cl /O2 /GL /D "NDEBUG" new.cpp /link /ltcg

java -server -Xmx1024m -Xms1024m -Xmn1023m Test n

java: Test 22 / Time: 1812 ms
cpp: Test 22 / Time: 2031 ms

java: Test 23 / Time: 3391 ms
cpp: Test 23 / Time: 4390 ms

java: Test 24 / Time: 7281 ms
cpp: Test 24 / Time: 10406 ms

java: Test 25 / Time: 14344 ms
cpp: Test 25 / Time: 22875 ms

java: Test 26 / CRTL-C
cpp: Test 26 / CRTL-C

I don't get the same results...
Odd. On my system, the C++ version beats java hand over fist wrt the
specific benchmark. Does Java require large amount of system memory to run
well? Could anybody else run the test? Also, have you tried tweaking any of
the settings? The java command line gives you a lot of options. Try the test
with something like:
# define REGION_DEPTH 7500000

# define SLAB_DEPTH 16384

# define SLAB_PRIME_DEPTH 4

# define SLAB_MAX_DEPTH 10
?
I think I will make a new post, and ask for others to post results. Thanks.

Jun 27 '08 #301
"Razii" <DO*************@hotmail.comwrote in message
news:s7********************************@4ax.com...
On Tue, 15 Apr 2008 15:56:40 -0700, "Chris Thomasson"
<cr*****@comcast.netwrote:
>>___________________________________________
java: Test 22 / Time: 2375 ms
vcpp: Test 22 / Time: 1468 ms
-------------------------------------------
java: Test 23 / Time: 3594 ms
vcpp: Test 23 / Time: 2362 ms
-------------------------------------------
java: Test 24 / Time: 33141 ms
vcpp: Test 24 / Time: 9390 ms
-------------------------------------------
java: Test 25 / CRTL-C <took longer than 1 min>
vcpp: Test 25 / Time: 26390 ms
-------------------------------------------
java: Test 26 / CRTL-C <took longer than 1 mins>
vcpp: Test 26 / CRTL-C <took longer than 1 mins>

http://pastebin.com/m45f642a5 (c++) Is that the right one?
http://pastebin.com/f3f559ae2 (java)

Hey Razii, you made a simple mistake with the java version linked to above.
It is hard-coded at CreateTree(22).

Jun 27 '08 #302
On Tue, 15 Apr 2008 19:58:06 -0700, "Chris Thomasson"
<cr*****@comcast.netwrote:
Does Java require large amount of system memory to run
well?
No, memory in your case should only effects n = 25. The C++ version
uses less memory and the OS doesn't go into page file (unlike java
version). For the rest of n < 25, memory size should have no effect.

The only difference seems to be that I am on athlon and you are on
Pentium.
># define REGION_DEPTH 7500000

# define SLAB_DEPTH 16384

# define SLAB_PRIME_DEPTH 4

# define SLAB_MAX_DEPTH 10
didn't see much difference with these..

new 22
Time: 2015 ms

new 23
Time: 4296 ms

new 23
Time: 4265 ms

new 24
Time: 9890 ms

new 25
Time: 22234 ms
Jun 27 '08 #303
On Tue, 15 Apr 2008 20:27:05 -0700, "Chris Thomasson"
<cr*****@comcast.netwrote:
>Hey Razii, you made a simple mistake with the java version linked to above.
It is hard-coded at CreateTree(22).
Yes, should have been http://pastebin.com/f2a6ecd3c
Jun 27 '08 #304
"Razii" <DO*************@hotmail.comwrote in message
news:fo********************************@4ax.com...
On Tue, 15 Apr 2008 19:58:06 -0700, "Chris Thomasson"eretta
<cr*****@comcast.netwrote:
>Does Java require large amount of system memory to run
well?

No, memory in your case should only effects n = 25. The C++ version
uses less memory and the OS doesn't go into page file (unlike java
version). For the rest of n < 25, memory size should have no effect.

The only difference seems to be that I am on athlon and you are on
Pentium.
Humm. Well, I know that "gpderetta" mentioned that his simple static region
allocator got 670 ms on his machine:

http://groups.google.com/group/comp....b34ca768579d83
This would be on CreateTree(22). Why did it get 2031 ms on your system?
Answer: I have know idea at all. ;^/
Weird inconclusive test results.

Jun 27 '08 #305

"Chris Thomasson" <cr*****@comcast.netwrote in message
news:5Z******************************@comcast.com. ..
"Razii" <DO*************@hotmail.comwrote in message
news:fo********************************@4ax.com...
>On Tue, 15 Apr 2008 19:58:06 -0700, "Chris Thomasson"eretta
<cr*****@comcast.netwrote:
>>Does Java require large amount of system memory to run
well?

No, memory in your case should only effects n = 25. The C++ version
uses less memory and the OS doesn't go into page file (unlike java
version). For the rest of n < 25, memory size should have no effect.

The only difference seems to be that I am on athlon and you are on
Pentium.

Humm. Well, I know that "gpderetta" mentioned that his simple static
region allocator got 670 ms on his machine:

http://groups.google.com/group/comp....b34ca768579d83
This would be on CreateTree(22). Why did it get 2031 ms on your system?
Answer: I have know idea at all. ;^/
Weird inconclusive test results.
Please note that I used his region allocator logic, with a heap depth of
5000000, for my third test which can be found here:

http://pastebin.com/m45f642a5

There is something weird going on here.

Jun 27 '08 #306

"Razii" <DO*************@hotmail.comwrote in message
news:fo********************************@4ax.com...
On Tue, 15 Apr 2008 19:58:06 -0700, "Chris Thomasson"
<cr*****@comcast.netwrote:
>Does Java require large amount of system memory to run
well?

No, memory in your case should only effects n = 25. The C++ version
uses less memory and the OS doesn't go into page file (unlike java
version). For the rest of n < 25, memory size should have no effect.

The only difference seems to be that I am on athlon and you are on
Pentium.
>># define REGION_DEPTH 7500000

# define SLAB_DEPTH 16384

# define SLAB_PRIME_DEPTH 4

# define SLAB_MAX_DEPTH 10

didn't see much difference with these..

new 22
Time: 2015 ms
[...]

This is bugging me because on my system the Test 22 got less than 1700 ms on
several runs. My old system which I ran the tests on must be slower than
yours. I have no idea what's going on.

Jun 27 '08 #307
On Tue, 15 Apr 2008 23:24:08 -0700, "Chris Thomasson"
<cr*****@comcast.netwrote:
>Humm. Well, I know that "gpderetta" mentioned that his simple static region
allocator got 670 ms on his machine:

http://groups.google.com/group/comp....b34ca768579d83
This would be on CreateTree(22). Why did it get 2031 ms on your system?
Answer: I have know idea at all. ;^/

his simplistic version

http://pastebin.com/m16980424 (this one)

did Time: 515 ms

on my computer. The one you posted didn't. That's why I asked you if
it's the right one.

In any case, the thread has become so long it's confusing to follow.
Perhaps post the best version along with java one in a different
thread so it's clear where and which version we are talking about.
Jun 27 '08 #308
On Wed, 16 Apr 2008 00:04:04 -0700, "Chris Thomasson"
<cr*****@comcast.netwrote:
>This is bugging me because on my system the Test 22 got less than 1700 ms on
several runs. My old system which I ran the tests on must be slower than
yours. I have no idea what's going on.
Maybe the link you gave me was wrong? Either I or you start a new
thread with the link and time. This thread is hard to follow.

As I said, this version...

http://pastebin.com/m16980424

did Time: 515 ms

Yours did 2000ms for n == 22

Jun 27 '08 #309
On Apr 16, 1:47 am, Razii <DONTwhatever...@hotmail.comwrote:
On Tue, 15 Apr 2008 16:06:16 -0700, "Chris Thomasson"

<cris...@comcast.netwrote:
I have now spent a total of 25 minutes creating these very simplistic
allocator designs for this benchmark Razii. I could spend some more and
really make some marked improvement in the overall performance, but I don't
think I want to do that... Like "gpderetta" says, nobody is paying me...

But isn't the problem that this allocator works with only one object,
only this tree? You have overloaded both the delete and new. How would
this work with applications that have dozens of classes and objects
that need to be created dynamically?
This (http://pastebin.com/m7765502c) is another arena based version.
It doesn't use typed pools (different types can freely use the same
pool), it takes memory from the system allocator and returns it to it
when it is done. It supports allocation of any size (it falls back to
malloc for huge sizes). It is withing 110% of the time for my previous
static typed region allocator.
The only problem is that the user must be careful with alignment (do
not allocate objects with different aligment without manually
padding). I could add automatic alignment, but it could waste a little
of space and it isn't worth it for this test.

Ah, it uses tr1::array. If your compiler doesn't have it, upgrade or
use boost::array instead. I could have coded a replacement (10 lines
maybe?) but didn't bother.

Does this satisfy your (arbitrary) constraints?

--
gpd
Jun 27 '08 #310
That thread became too big for me to follow, so we continue here.

C++ version by Chris Thomasson
http://pastebin.com/m45f642a5

http://pastebin.com/f3f559ae2 (java version)

(must use something like this with java version)
java -server -Xmx1024m -Xms1024m -Xmn1023m Test n

cl /O2 /GL test.cpp /link /ltcg

n = 22 Time: 1765 ms (C++)

cl /O2 /GL /D "NDEBUG" new.cpp /link /ltcg
n = 22 Time: 2046 ms (C++)

what? C++ version got slower by adding /D "NDEBUG" as a flag?

that might be the reason, Chris, why you got different result than me.
g++ -O2 -fomit-frame-pointer -finline-functions "new.cpp" -o "new.ex
e"

(02AB0048/1) - Slab Prime
Time: 1766 ms
(02AB0048/0) - Slab Dtor

g++ -O2 -DNDEBUG -fomit-frame-pointer -finline-functions "new.cpp" -
o "new.exe"

new 22 Time: 2203 ms

Samething happened with g++
Jun 27 '08 #311
>http://pastebin.com/f3f559ae2 (java version)
Should have been .. http://pastebin.com/f2a6ecd3c

>C++ version by Chris Thomasson
http://pastebin.com/m45f642a5
Is there an explanation why adding

-DNDEBUG flag makes C++ version slower?
Jun 27 '08 #312

Razii wrote:
That thread became too big for me to follow, so we continue here.
great! jackass.
Jun 27 '08 #313
On Apr 16, 2:09 pm, Razii <DONTwhatever...@hotmail.comwrote:
http://pastebin.com/f3f559ae2(java version)

Should have been ..http://pastebin.com/f2a6ecd3c
C++ version by Chris Thomasson
http://pastebin.com/m45f642a5

Is there an explanation why adding

-DNDEBUG flag makes C++ version slower?
Actually yes. The expansion of the macro assert(condition) you have
branch like this:

if(!condition) abort();

If the compiler is smart enough to know that abort() has the special
side effect to terminate the program (for example gcc does),
the compiler can assume that after the call to assert, condition is
guaranteed to hold and optimize accordingly.
If condition is very simple, assert itself is extremely cheap (the if
is always not taken in a bug free program, so it is always predicted
perfectly).
As asied note, Visual C++ has __assume(condition) that gives to the
compiler the same information but never evaluates condition.

Of course this is a kind-of-wild guess. It could just that the assert
add enough random noise that the generated assembler is by chance a
bit faster on your machine.

--
Giovanni P. Deretta

Jun 27 '08 #314
On Wed, 16 Apr 2008 05:26:26 -0700 (PDT), gpderetta
<gp*******@gmail.comwrote:
>Of course this is a kind-of-wild guess. It could just that the assert
add enough random noise that the generated assembler is by chance a
bit faster on your machine.
Can you post what time you get with his C++ version? He doesn't seem
to believe that his version is slower (only with NDEBUG flag --
otherwise it's a bit faster).
Jun 27 '08 #315
On Apr 16, 1:57 pm, Razii <DONTwhatever...@hotmail.comwrote:
That thread became too big for me to follow, so we continue here.

C++ version by Chris Thomassonhttp://pastebin.com/m45f642a5

http://pastebin.com/f3f559ae2(java version)
[...]
gè++ -O2 -fomit-frame-pointer -finline-functions "new.cpp" -o "new.ex
e"
I get much better timing with Chris version if I use -O3:
g++ -v:
gcc version 4.3.0 20070916 (experimental)

/usr/lib/gcc-snapshot/bin/g++ new.cc -O3 -fomit-frame-pointer

new 22:
Time: 1140 ms

/usr/lib/gcc-snapshot/bin/g++ new.cc -O2 -fomit-frame-pointer

new 22:
Time: 2040 ms

--
Giovanni P. Deretta
Jun 27 '08 #316
On Wed, 16 Apr 2008 08:23:55 -0400, "Jeff Higgins"
<oo*******@yahoo.comwrote:
>great! jackass.
*PLONK*
Jun 27 '08 #317
On Wed, 16 Apr 2008 05:37:27 -0700 (PDT), gpderetta
<gp*******@gmail.comwrote:
>I get much better timing with Chris version if I use -O3:
g++ -v:
Yes, I do too ( 1600 ms). What happens when you do n=23 though (since
you didn't have -DNDEBUG)

Without -DNDEBUG I get; n=23

(04520600/6) - Slab Destroy
(044C05D0/5) - Slab Dtor
(04400570/4) - Slab Dtor
(042804B0/3) - Slab Dtor
(03F80330/2) - Slab Dtor
(05310140/1) - Slab Dtor
(036602A0/0) - Slab Dtor
^C

Jun 27 '08 #318
On Apr 16, 2:36 pm, Razii <DONTwhatever...@hotmail.comwrote:
On Wed, 16 Apr 2008 05:26:26 -0700 (PDT), gpderetta

<gpdere...@gmail.comwrote:
Of course this is a kind-of-wild guess. It could just that the assert
add enough random noise that the generated assembler is by chance a
bit faster on your machine.

Can you post what time you get with his C++ version? He doesn't seem
to believe that his version is slower (only with NDEBUG flag --
otherwise it's a bit faster).
C++ version by Chris Thomasson (http://pastebin.com/m45f642a5):

g++ new.cc -O3 -fomit-frame-pointer -DNDEBUG
new 22: Time: 1500 ms

g++ new.cc -O3 -fomit-frame-pointer
new 22: Time: 1140 ms

I have tried to change the program by unconditionally defining
DBG_PRINTF as printf. Now both with and without NDEBUG the program run
fast (~1140 ms). So the problem is not assert, but just gcc optimizer
behaving funny. Werid.

--
Giovanni P. Deretta
Jun 27 '08 #319
Lew
gpderetta wrote:
On Apr 16, 1:57 pm, Razii <DONTwhatever...@hotmail.comwrote:
>That thread became too big for me to follow, so we continue here.

C++ version by Chris Thomassonhttp://pastebin.com/m45f642a5

http://pastebin.com/f3f559ae2(java version)
[...]
gè++ -O2 -fomit-frame-pointer -finline-functions "new.cpp" -o "new.ex
e"

I get much better timing with Chris version if I use -O3:
g++ -v:
gcc version 4.3.0 20070916 (experimental)

/usr/lib/gcc-snapshot/bin/g++ new.cc -O3 -fomit-frame-pointer

new 22:
Time: 1140 ms

/usr/lib/gcc-snapshot/bin/g++ new.cc -O2 -fomit-frame-pointer

new 22:
Time: 2040 ms
Very interesting C++ conversation.

--
Lew
Jun 27 '08 #320
On Apr 16, 2:54 pm, Razii <DONTwhatever...@hotmail.comwrote:
On Wed, 16 Apr 2008 05:37:27 -0700 (PDT), gpderetta

<gpdere...@gmail.comwrote:
I get much better timing with Chris version if I use -O3:
g++ -v:

Yes, I do too ( 1600 ms). What happens when you do n=23 though (since
you didn't have -DNDEBUG)

Without -DNDEBUG I get; n=23
Modified Chris version with printf unconditionally compiled in:
g++ create_tree.cc -O3 -fomit-frame-pointer -DNDEBUG

n=23:

<lotsa debug info>
Time: 2890 ms

Compiling out the printf I get

Time: Time: 3430 ms

Werid! BTW, did you try my version (http://pastebin.com/m7765502c)?

--
gpd
Jun 27 '08 #321
On Apr 16, 3:04 pm, Lew <l...@lewscanon.comwrote:
gpderetta wrote:
On Apr 16, 1:57 pm, Razii <DONTwhatever...@hotmail.comwrote:
That thread became too big for me to follow, so we continue here.
C++ version by Chris Thomassonhttp://pastebin.com/m45f642a5
>http://pastebin.com/f3f559ae2(javaversion)
[...]
gè++ -O2 -fomit-frame-pointer -finline-functions "new.cpp" -o "new.ex
e"
I get much better timing with Chris version if I use -O3:
g++ -v:
gcc version 4.3.0 20070916 (experimental)
/usr/lib/gcc-snapshot/bin/g++ new.cc -O3 -fomit-frame-pointer
new 22:
Time: 1140 ms
/usr/lib/gcc-snapshot/bin/g++ new.cc -O2 -fomit-frame-pointer
new 22:
Time: 2040 ms

Very interesting C++ conversation.
Agree on the interesting :), but it is actually C++: we are trying to
see which is the fastest C++ useless [1] allocator!

--
Giovanni P. Deretta
Jun 27 '08 #322
On Wed, 16 Apr 2008 06:08:27 -0700 (PDT), gpderetta
<gp*******@gmail.comwrote:
>Werid! BTW, did you try my version (http://pastebin.com/m7765502c)?
yes, didn't compile...

new.cpp:26: error: 'buffer__size' was not declared in this scope
new.cpp:30: error: '(-1073741824u / ((unsigned
int)region::buffer_byte_size))' i
s not a valid template argument for type 'unsigned int' because it is
a non-cons
tant expression
new.cpp: In member function 'void region::add_buffer()':
new.cpp:51: error: invalid types 'int[size_t]' for array subscript
new.cpp:52: error: invalid types 'int[size_t]' for array subscript
new.cpp:54: error: invalid types 'int[size_t]' for array subscript
new.cpp: In member function 'void region::free()':
new.cpp:70: error: request for member 'size' in
'((region*)this)->region::m_buff
ers', which is of non-class type 'int'
new.cpp:71: error: invalid types 'int[size_t]' for array subscript
new.cpp:73: error: request for member 'size' in
'((region*)this)->region::m_buff
ers', which is of non-class type 'int'
new.cpp:74: error: invalid types 'int[size_t]' for array subscript
new.cpp: In constructor 'region::region()':
new.cpp:95: error: request for member 'size' in
'((region*)this)->region::m_buff
ers', which is of non-class type 'int'
new.cpp:95: error: invalid types 'int[size_t]' for array subscript
Jun 27 '08 #323
On Apr 16, 3:28 pm, Razii <DONTwhatever...@hotmail.comwrote:
On Wed, 16 Apr 2008 06:08:27 -0700 (PDT), gpderetta

<gpdere...@gmail.comwrote:
Werid! BTW, did you try my version (http://pastebin.com/m7765502c)?

yes, didn't compile...

new.cpp:26: error: 'buffer__size' was not declared in this scope
new.cpp:30: error: '(-1073741824u / ((unsigned
int)region::buffer_byte_size))' i
s not a valid template argument for type 'unsigned int' because it is
a non-cons
tant expression
new.cpp: In member function 'void region::add_buffer()':
new.cpp:51: error: invalid types 'int[size_t]' for array subscript
new.cpp:52: error: invalid types 'int[size_t]' for array subscript
new.cpp:54: error: invalid types 'int[size_t]' for array subscript
new.cpp: In member function 'void region::free()':
new.cpp:70: error: request for member 'size' in
'((region*)this)->region::m_buff
ers', which is of non-class type 'int'
new.cpp:71: error: invalid types 'int[size_t]' for array subscript
new.cpp:73: error: request for member 'size' in
'((region*)this)->region::m_buff
ers', which is of non-class type 'int'
new.cpp:74: error: invalid types 'int[size_t]' for array subscript
new.cpp: In constructor 'region::region()':
new.cpp:95: error: request for member 'size' in
'((region*)this)->region::m_buff
ers', which is of non-class type 'int'
new.cpp:95: error: invalid types 'int[size_t]' for array subscript
Sorry, I keep posting broken versions :(.
Try this http://pastebin.com/m2649e007

--
Giovanni P. Deretta
Jun 27 '08 #324
On Wed, 16 Apr 2008 06:35:49 -0700 (PDT), gpderetta
<gp*******@gmail.comwrote:
>Sorry, I keep posting broken versions :(.
Try this http://pastebin.com/m2649e007
n = 20
Time: 406 ms (vs java Time: 531 ms)

n = 21
Time: 781 ms (vs java Time: 1000 ms)

n = 22
Time: 1781 ms (vs java Time: 1797 ms)

n = 23
Time: 3718 ms (vs java Time: 3375 ms)

n = 24
Time: 9093 ms (vs java Time: 7188 ms)

n = 25
Time: 22312 ms (vs java Time: 13422 ms)
Jun 27 '08 #325
On Apr 10, 9:16*pm, Razii <DONTwhatever...@hotmail.comwrote:
On Thu, 10 Apr 2008 08:50:06 -0700 (PDT), lbonaf...@yahoo.com wrote:
You still have to worry about leaking memory (and dereferencing null
pointers) in languages like Java.
http://www.ibm.com/developerworks/li...aks/index.html

True memory leaks memory are impossible, other than by holding
references to objects that are not needed.
If I'm allowed to define what is meant by "true memory leaks" I could
say the same for any language. I've never seen a puddle of memory
under my computer after running any piece of software. :-)
Jun 27 '08 #326
"Razii" <DO*************@hotmail.comwrote in message
news:b5********************************@4ax.com...
On Tue, 15 Apr 2008 23:24:08 -0700, "Chris Thomasson"
<cr*****@comcast.netwrote:
>>Humm. Well, I know that "gpderetta" mentioned that his simple static
region
allocator got 670 ms on his machine:

http://groups.google.com/group/comp....b34ca768579d83
This would be on CreateTree(22). Why did it get 2031 ms on your system?
Answer: I have know idea at all. ;^/


his simplistic version

http://pastebin.com/m16980424 (this one)

did Time: 515 ms

on my computer. The one you posted didn't. That's why I asked you if
it's the right one.
If you look carefully at the region_allocator class in
<http://pastebin.com/m45f642a5you will see where I basically use the same
exact thing as his simplistic version. I don't know what's going on. On my
system, it consistentaly outperforms the Java version. The only thing I can
think of is that Java does not like to run on systems with only 512mb ram.

In any case, the thread has become so long it's confusing to follow.
Perhaps post the best version along with java one in a different
thread so it's clear where and which version we are talking about.
Jun 27 '08 #327
"Razii" <DO*************@hotmail.comwrote in message
news:v5********************************@4ax.com...
On Wed, 16 Apr 2008 00:04:04 -0700, "Chris Thomasson"
<cr*****@comcast.netwrote:
>>This is bugging me because on my system the Test 22 got less than 1700 ms
on
several runs. My old system which I ran the tests on must be slower than
yours. I have no idea what's going on.

Maybe the link you gave me was wrong? Either I or you start a new
thread with the link and time. This thread is hard to follow.

As I said, this version...

http://pastebin.com/m16980424

did Time: 515 ms

Yours did 2000ms for n == 22
When I run this version on my machine http://pastebin.com/m45f642a5

I consistently get times ranging from 1300 - 1650 ms. I don't know why it
runs slower on your machine.

Jun 27 '08 #328
"Razii" <DO*************@hotmail.comwrote in message
news:fi********************************@4ax.com...
On Wed, 16 Apr 2008 05:26:26 -0700 (PDT), gpderetta
<gp*******@gmail.comwrote:
>>Of course this is a kind-of-wild guess. It could just that the assert
add enough random noise that the generated assembler is by chance a
bit faster on your machine.

Can you post what time you get with his C++ version? He doesn't seem
to believe that his version is slower (only with NDEBUG flag --
otherwise it's a bit faster).
Are you saying that my version <http://pastebin.com/m45f642a5beats Java by
a few milliseconds on your system _only_ when you compile it _without_
defining NDEBUG? That's so weird. Could you please try and compile it with
VC9, and post results? On my system, I am compiling it with VC8. I remember
that you mentioned that VC9 gave my second try faster results:

http://groups.google.com/group/comp....a3b5ff7bc56d7f
So could you compile http://pastebin.com/m45f642a5 with VC9 and post results
please?

Jun 27 '08 #329
"gpderetta" <gp*******@gmail.comwrote in message
news:2a**********************************@59g2000h sb.googlegroups.com...
On Apr 16, 2:54 pm, Razii <DONTwhatever...@hotmail.comwrote:
>On Wed, 16 Apr 2008 05:37:27 -0700 (PDT), gpderetta

<gpdere...@gmail.comwrote:
>I get much better timing with Chris version if I use -O3:
g++ -v:

Yes, I do too ( 1600 ms). What happens when you do n=23 though (since
you didn't have -DNDEBUG)

Without -DNDEBUG I get; n=23

Modified Chris version with printf unconditionally compiled in:
g++ create_tree.cc -O3 -fomit-frame-pointer -DNDEBUG

n=23:

<lotsa debug info>
Time: 2890 ms

Compiling out the printf I get

Time: Time: 3430 ms

Werid!
Wierd indeed.
BTW, did you try my version (http://pastebin.com/m7765502c)?
Jun 27 '08 #330
"gpderetta" <gp*******@gmail.comwrote in message
news:b0**********************************@l42g2000 hsc.googlegroups.com...
On Apr 16, 3:04 pm, Lew <l...@lewscanon.comwrote:
gpderetta wrote:
On Apr 16, 1:57 pm, Razii <DONTwhatever...@hotmail.comwrote:
>That thread became too big for me to follow, so we continue here.
>C++ version by Chris Thomassonhttp://pastebin.com/m45f642a5
>>http://pastebin.com/f3f559ae2(javaversion)
>[...]
>gè++ -O2 -fomit-frame-pointer -finline-functions "new.cpp" -o "new.ex
>e"
I get much better timing with Chris version if I use -O3:
g++ -v:
gcc version 4.3.0 20070916 (experimental)
/usr/lib/gcc-snapshot/bin/g++ new.cc -O3 -fomit-frame-pointer
new 22:
Time: 1140 ms
/usr/lib/gcc-snapshot/bin/g++ new.cc -O2 -fomit-frame-pointer
new 22:
Time: 2040 ms
Very interesting C++ conversation.
Agree on the interesting :), but it is actually C++: we are trying to
see which is the fastest C++ useless [1] allocator!
LOL!

Jun 27 '08 #331
"Razii" <DO*************@hotmail.comwrote in message
news:us********************************@4ax.com...
On Wed, 16 Apr 2008 06:35:49 -0700 (PDT), gpderetta
<gp*******@gmail.comwrote:
>>Sorry, I keep posting broken versions :(.
Try this http://pastebin.com/m2649e007

n = 20
Time: 406 ms (vs java Time: 531 ms)

n = 21
Time: 781 ms (vs java Time: 1000 ms)

n = 22
Time: 1781 ms (vs java Time: 1797 ms)

n = 23
Time: 3718 ms (vs java Time: 3375 ms)

n = 24
Time: 9093 ms (vs java Time: 7188 ms)

n = 25
Time: 22312 ms (vs java Time: 13422 ms)
His version is hardcoded at CreateTree(23). Did you modify it to process
command line args?

Jun 27 '08 #332
"gpderetta" <gp*******@gmail.comwrote in message
news:bc**********************************@a70g2000 hsh.googlegroups.com...
On Apr 16, 2:36 pm, Razii <DONTwhatever...@hotmail.comwrote:
>On Wed, 16 Apr 2008 05:26:26 -0700 (PDT), gpderetta

<gpdere...@gmail.comwrote:
>Of course this is a kind-of-wild guess. It could just that the assert
add enough random noise that the generated assembler is by chance a
bit faster on your machine.

Can you post what time you get with his C++ version? He doesn't seem
to believe that his version is slower (only with NDEBUG flag --
otherwise it's a bit faster).

C++ version by Chris Thomasson (http://pastebin.com/m45f642a5):

g++ new.cc -O3 -fomit-frame-pointer -DNDEBUG
new 22: Time: 1500 ms

g++ new.cc -O3 -fomit-frame-pointer
new 22: Time: 1140 ms

I have tried to change the program by unconditionally defining
DBG_PRINTF as printf. Now both with and without NDEBUG the program run
fast (~1140 ms). So the problem is not assert, but just gcc optimizer
behaving funny. Werid.
Strange. Well, ~1140ms beats Java with N=22 according to the timings posted
Razii:

http://groups.google.com/group/comp....e293f8b5a86479

He said that Java N=22 got 1797 ms.

Jun 27 '08 #333
On Wed, 16 Apr 2008 10:58:34 -0700, "Chris Thomasson"
<cr*****@comcast.netwrote:
>n = 20
Time: 406 ms (vs java Time: 531 ms)

n = 21
Time: 781 ms (vs java Time: 1000 ms)

n = 22
Time: 1781 ms (vs java Time: 1797 ms)

n = 23
Time: 3718 ms (vs java Time: 3375 ms)

n = 24
Time: 9093 ms (vs java Time: 7188 ms)

n = 25
Time: 22312 ms (vs java Time: 13422 ms)

His version is hardcoded at CreateTree(23). Did you modify it to process
command line args?
Hmm.. I was sure I copied and pasted the right one but I guess not.
The above is not right. The times for his versions (after changing
CreateTree<0>(n)) are...

n = 20 -- 343 ms
n = 21 -- 734 ms
n = 22 -- 1421 ms
n = 23 -- 2875 ms
n = 24 -- 5812 ms
n = 25 -- 11546ms
Jun 27 '08 #334
On Wed, 16 Apr 2008 06:35:49 -0700 (PDT), gpderetta
<gp*******@gmail.comwrote:
>Sorry, I keep posting broken versions :(.
Try this http://pastebin.com/m2649e007
what if I change struct to class? i.e,

class Tree {
Tree * left;
Tree * right;

void * operator new(size_t) {
return region::current->allocate(sizeof(Tree));
}
none of yours Chris versions work then.

Jun 27 '08 #335
"Razii" <DO*************@hotmail.comwrote in message
news:es********************************@4ax.com...
On Wed, 16 Apr 2008 06:35:49 -0700 (PDT), gpderetta
<gp*******@gmail.comwrote:
>>Sorry, I keep posting broken versions :(.
Try this http://pastebin.com/m2649e007

what if I change struct to class? i.e,

class Tree {
Tree * left;
Tree * right;

void * operator new(size_t) {
return region::current->allocate(sizeof(Tree));
}
none of yours Chris versions work then.
Why would my version <http://pastebin.com/m45f642a5work with the above?
You just made everything private. The CreateTree and DeleteTree functions
require access to these members. Change it to:
class Tree {
public:
Tree * left;
Tree * right;
[...]
Or make the CreateTree and DeleteTree functions friends of the Tree object.

Jun 27 '08 #336
On Fri, 18 Apr 2008 15:50:33 -0700, "Chris Thomasson"
<cr*****@comcast.netwrote:
>Why would my version <http://pastebin.com/m45f642a5work with the above?
You just made everything private.
Yes, it worked. There was not much difference between struct and class
in this class.

Jun 27 '08 #337
Razii wrote:
On Fri, 18 Apr 2008 15:50:33 -0700, "Chris Thomasson"
<cr*****@comcast.netwrote:
>Why would my version <http://pastebin.com/m45f642a5work with the above?
You just made everything private.

Yes, it worked. There was not much difference between struct and class
in this class.
Why did you expect there to be? There should be no difference at all.

Do you actually know any C++?

--
Ian Collins.
Jun 27 '08 #338
Lew
Chris Thomasson wrote:
"Razii" <DO*************@hotmail.comwrote in message
news:es********************************@4ax.com...
>On Wed, 16 Apr 2008 06:35:49 -0700 (PDT), gpderetta
<gp*******@gmail.comwrote:
>>Sorry, I keep posting broken versions :(.
Try this http://pastebin.com/m2649e007

what if I change struct to class? i.e,

class Tree {
Tree * left;
Tree * right;

void * operator new(size_t) {
return region::current->allocate(sizeof(Tree));
}
none of yours Chris versions work then.

Why would my version <http://pastebin.com/m45f642a5work with the
above? You just made everything private. The CreateTree and DeleteTree
functions require access to these members. Change it to:
class Tree {
public:
Tree * left;
Tree * right;
[...]
Or make the CreateTree and DeleteTree functions friends of the Tree object.
Excellent advice.

--
Lew
Jun 27 '08 #339
Lew
Ian Collins wrote:
Razii wrote:
>On Fri, 18 Apr 2008 15:50:33 -0700, "Chris Thomasson"
<cr*****@comcast.netwrote:
>>Why would my version <http://pastebin.com/m45f642a5work with the above?
You just made everything private.
Yes, it worked. There was not much difference between struct and class
in this class.
Why did you expect there to be? There should be no difference at all.

Do you actually know any C++?
I used to. It's been a while. That's made this conversation quite interesting.

--
Lew
Jun 27 '08 #340
On Sat, 19 Apr 2008 12:43:44 +1200, Ian Collins <ia******@hotmail.com>
wrote:
>Why did you expect there to be? There should be no difference at all.
Well, at least the C does not have actual objects and strucs are much
lighter weight at the cost of being less useful than objects.
Jun 27 '08 #341
Razii wrote:
On Sat, 19 Apr 2008 12:43:44 +1200, Ian Collins <ia******@hotmail.com>
wrote:
>Why did you expect there to be? There should be no difference at all.

Well, at least the C does not have actual objects and strucs are much
lighter weight at the cost of being less useful than objects.
Now what are you blithering on about?

A valid C struct is a valid C++ struct.

--
Ian Collins.
Jun 27 '08 #342

"Ian Collins" <ia******@hotmail.comwrote in message
news:66*************@mid.individual.net...
Razii wrote:
>On Sat, 19 Apr 2008 12:43:44 +1200, Ian Collins
<ia******@hotmail.com>
wrote:
>>Why did you expect there to be? There should be no difference at
all.

Well, at least the C does not have actual objects and strucs are much
lighter weight at the cost of being less useful than objects.
Now what are you blithering on about?

A valid C struct is a valid C++ struct.
That is an incorrect statement.

The creators of C++ went to great lengths to make C++ structs look and
feel like C structs but there are differences.
A struct in C++ is nothing more than a class with default public access.
C++ structs have constructors/destructors. If you don't define them the
compiler will do it for you.
You can subclass a struct.
You can have virtual methods (you can actually have methods in the
struct)

Just because you can use the same C syntax when using C++ structs, don't
make the mistake of think that they are one and the same.

In C you could assign one struct to another and you got a straight
memory copy.
In C++ it calls the assignment operator.
Of course, if you forgot to write one the Compiler will create one for
you (that does a straight memory copy)

A C++ struct is NOT a "lightweight class" as many like to use it.
A class/struct can be equally heavy/light depending on usage.

C structs on the other hand ARE lighter weight.
No Vtable
No inheritance
No constructor/destructor
Bill
Jun 27 '08 #343
Lew
Bill Butler wrote:
A C++ struct is NOT a "lightweight class" as many like to use it.
A class/struct can be equally heavy/light depending on usage.

C structs on the other hand ARE lighter weight.
No Vtable
No inheritance
No constructor/destructor
--
Lew
Jun 27 '08 #344
Bill Butler wrote:
"Ian Collins" <ia******@hotmail.comwrote:
>>
A valid C struct is a valid C++ struct.

That is an incorrect statement.
No, it was a correct statement. Otherwise it would be impossible to use
any C++ code that used the C standard library.
The creators of C++ went to great lengths to make C++ structs look and
feel like C structs but there are differences.
There are additions the programmer can make, but a vanilla C struct is
the same in C as it is in C++. Otherwise we would not be able to mix C
and C++ code using the same struct declarations.
A struct in C++ is nothing more than a class with default public access.
Did I say otherwise?
C++ structs have constructors/destructors. If you don't define them the
compiler will do it for you.
A POD (C) struct does not require any. There is nothing to initialise
or destroy.
You can subclass a struct.
So?
You can have virtual methods (you can actually have methods in the
struct)
Not if it's a legal C struct.
Just because you can use the same C syntax when using C++ structs, don't
make the mistake of think that they are one and the same.
It's not a mistake.
In C you could assign one struct to another and you got a straight
memory copy.
In C++ it calls the assignment operator.
If you define one.
A C++ struct is NOT a "lightweight class" as many like to use it.
I don't know any that do.
A class/struct can be equally heavy/light depending on usage.
I never said otherwise.
C structs on the other hand ARE lighter weight.
No Vtable
No inheritance
No constructor/destructor
As they are when compiled as C++.

--
Ian Collins.
Jun 27 '08 #345
"Lew" <le*@lewscanon.comwrote in message
news:Td******************************@comcast.com. ..
Chris Thomasson wrote:
[...]
>>See, I thought that he meant count from a single base of memory. In

At any given moment, that is how the JVM allocates memory.
>>other words, increment a pointer. This can be analogous to a counter.
Think in terms of using FAA to increment a pointer location off of
common base memory. This can definitely be used for an allocator that
does not really like to free anything... How would you do it? I bet you
would not use this method.

I let the JVM do it, since it takes only about 10 machine instructions to
allocate an object, and guarantees the result to be thread safe.
This implies that its using distributed per-thread memory allocation
technique, or global pointer(s). The former can be implemented, on say a
x86, with simple MOV instructions. The latter, well, its going to have to
use a 'LOCK
XADD', or other interlocked RMW, which is way more expensive. Knowing the
smart people that implement Java at SUN, their using distributed methods
indeed. In fact, you can take a look at their source code...

Jun 27 '08 #346
Lew
Ian Collins wrote:
Bill Butler wrote:
>"Ian Collins" <ia******@hotmail.comwrote:
>> C C++
C++ code C standard
>C++ C++ look and
feel like C

C
C C++. C
C++ code
> C++
C++
(C)
>>
C
> C syntax C++ structs,
>C
In C++
>C++
>C
C++.
--
Lew
Jun 27 '08 #347

"Lew" <le*@lewscanon.comwrote in message
news:Tc******************************@comcast.com. ..
Ian Collins wrote:
>Bill Butler wrote:
>>"Ian Collins" <ia******@hotmail.comwrote:
C C++
>C++ code C standard
>>C++ C++ look and feel like C

C C C++. C
C++ code
>> C++
C++
(C)
<snip>

Si, I see what you mean.
Jun 27 '08 #348
EJP
Bill Butler wrote:
In C++ it calls the assignment operator.
Of course, if you forgot to write one the Compiler will create one for
you (that does a straight memory copy)
Actually the generated assigment operator calls the assignment operator
on all the members, and so on recursively, which may or may not
ultimately result in a straight memory copy depending on whether any
application-defined assignment operators are reached.
Jun 27 '08 #349
"EJP" <es*************@not.bigpond.comwrote in message
news:_X*****************@news-server.bigpond.net.au...
Bill Butler wrote:
>In C++ it calls the assignment operator.
Of course, if you forgot to write one the Compiler will create one
for you (that does a straight memory copy)

Actually the generated assigment operator calls the assignment
operator on all the members, and so on recursively, which may or may
not ultimately result in a straight memory copy depending on whether
any application-defined assignment operators are reached.
Correct, I was thinking about structs with only primitives members.
Thanks for the correction.
Jun 27 '08 #350

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bob | last post by:
Are there any known applications out there used to test the performance of the .NET garbage collector over a long period of time? Basically I need an application that creates objects, uses them, and...
4
by: Pedro Miguel Carvalho | last post by:
Greetings. I'm creating a project that as a intricate relation between object kind of like a set where each object in the set can be connect to a subset of object of the set and objects not in...
10
by: pachanga | last post by:
The Hans-Boehm garbage collector can be successfully used with C and C++, but not yet a standard for C++.. Is there talks about Garbage Collector to become in the C++ standard?
5
by: Ben | last post by:
Could someone please verify if what I am doing as follow is corrected: 1. when dealing with custom class objects: ..... public myObject as myClass myObject as New myClass .......here I am...
13
by: Mingnan G. | last post by:
Hello everyone. I have written a garbage collector for standard C++ application. It has following main features. 1) Deterministic Finalization Providing deterministic finalization, the system...
28
by: Goalie_Ca | last post by:
I have been reading (or at least googling) about the potential addition of optional garbage collection to C++0x. There are numerous myths and whatnot with very little detailed information. Will...
142
by: jacob navia | last post by:
Abstract -------- Garbage collection is a method of managing memory by using a "collector" library. Periodically, or triggered by an allocation request, the collector looks for unused memory...
8
by: Paul.Lee.1971 | last post by:
Hi everyone, A program that I'm helping to code seems to slow down drastically during initialisation, and looking at the profiling graph, it seems to be the garbage collector thats slowing things...
56
by: Johnny E. Jensen | last post by:
Hellow I'am not sure what to think about the Garbage Collector. I have a Class OutlookObject, It have two private variables. Private Microsoft.Office.Interop.Outlook.Application _Application =...
46
by: Carlo Milanesi | last post by:
Hello, traditionally, in C++, dynamically allocated memory has been managed explicitly by calling "delete" in the application code. Now, in addition to the standard library strings, containers,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.