Le 22/05/12 08:05, Juha Nieminen a écrit :
> Ian Collins<ian-> wrote:
>> Rather than fussing over a few bytes, how about a performance comparison?
>
> A performance comparison would be quite moot because the biggest bottleneck
> in the whole thing is memory allocation. By far.
Yes. With a fast allocator, my software runs at the same
speed than C++. This due to bottleneck is in:
Memory I/O
Allocation
> A performance comparison
> would only make sense if one version uses more memory allocations than the
> other (for example, I have seen "generic" linked lists in C that actually
> make two allocations per element rather than the one that std::list makes,
> hence basically making the C version twice as slow as std::list).
>
My software makes one allocation per element.
> It can be quite surprising how much time the program spends in memory
> allocation alone. For instance, if you instantiate a std::set and add
> some tens of millions of elements to it, it will take many seconds on
> a typical computer. You'd think that the majority of the time is spent
> re-balancing the tree after each insertion. You'd be wrong. Something
> like 80-90% of the time is spent allocating memory!
>
That number is correct, that's why I decided to use (for single linked
lists)
struct element {
struct element *Next;
char data[1];
};
> Using a very fast allocator with std::set or std::list can speed it up
> quite considerably, if many insertions and deletions are performed.
> (The great thing about the C++ standard data containers is that they
> support user-created memory allocators, something that's way more
> difficult to do in a "generic" C container; as everything else.)
My software supports user supplied allocators. The default allocator
object is:
typedef struct tagAllocator {
void *(*malloc)(size_t); /* Function to allocate memory */
void (*free)(void *); /* Function to release it */
void *(*realloc)(void *,size_t);/* Function to resize a block of
memory */
void *(*calloc)(size_t,size_t);
} ContainerAllocator;
You can replace it with your own allocator. For instance you can
supply a GC (Boehm's for instance) allocator, or a custom one,
as you wish.
|