More embarrassing microbenchmars for D's GC.
Leandro Lucarella
llucax at gmail.com
Mon Jun 9 13:34:08 PDT 2008
I've done a very simple microbenchmark testing a single linked list.
What the test does is fill the list with long elements, and then iterate
the list and increment the associated value. This test mostly test the
allocation speed.
I've done plain a C version, a C++ version (using STL double-linked list,
so it has some disvantage here), a D version without using the GC, a D
version using the GC, and a Python version.
Here are the result (Celeron ~2GHz, 1M elements, average from 3 runs):
C C++ D no gc D gc D gc dis Python
Fill 0.136136 0.142705 0.131238 22.628577 0.242637 12.952816
Inc 0.025134 0.038768 0.037456 0.050480 0.051545 3.765271
Total 0.161270 0.181473 0.168694 22.679057 0.294182 16.718087
Results are in seconds, compiled with gcc/g++/gdc (-O3 -finline, plus
-frelease for D code). Using phobos (gdc 0.25-20080419-4.1.2-22, with
debian patches).
You can see Python is almost twice faster than D doing allocation (and the
python example has some intentional overhead to make it as close as D code
as possible, using more Pythonic code could yield better results).
But there are a few other results I can't explain:
1) Why is D gc (disabled or not) version ~25% slower than the D version
that uses malloc when iterating the list? It shouldn't be any GC
activity in that part. Could be some GC locallity issue that yields
more cache misses?
2) Why is D malloc version ~33% slower than the C version? I took a look
at the generated assembly and it's almost identical:
<_Dmain+198>: lea -0x20(%ebp),%eax
<_Dmain+201>: lea 0x0(%esi,%eiz,1),%esi
<_Dmain+208>: addl $0x1,0x8(%eax)
<_Dmain+212>: adcl $0x0,0xc(%eax)
<_Dmain+216>: mov (%eax),%eax
<_Dmain+218>: test %eax,%eax
<_Dmain+220>: jne 0x804a240 <_Dmain+208>
<main+248>: lea -0x1c(%ebp),%eax
<main+251>: nop
<main+252>: lea 0x0(%esi,%eiz,1),%esi
<main+256>: addl $0x1,0x4(%eax)
<main+260>: adcl $0x0,0x8(%eax)
<main+264>: mov (%eax),%eax
<main+266>: test %eax,%eax
<main+268>: jne 0x8048550 <main+256>
<main+270>: movl $0x0,0x4(%esp)
<main+278>: movl $0x8049800,(%esp)
Tests attached.
--
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
RENUNCIO PARA IR A REZARLE A SAN CAYETANO
-- Crónica TV
-------------- next part --------------
A non-text attachment was scrubbed...
Name: list-test-c.c
Type: text/x-csrc
Size: 767 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20080609/73f01525/attachment.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: list-test-cpp.cpp
Type: text/x-c++src
Size: 577 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20080609/73f01525/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: list-test-d-gc.d
Type: text/x-dsrc
Size: 1306 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20080609/73f01525/attachment.d>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: list-test-d.d
Type: text/x-dsrc
Size: 1275 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20080609/73f01525/attachment-0001.d>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: list-test-py.py
Type: text/x-python
Size: 661 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20080609/73f01525/attachment.py>
More information about the Digitalmars-d
mailing list