Re: [gtk-list] Re: how can I trust glib when it has so many mem leaks?
- From: Kevin Handy <kth srv net>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Re: how can I trust glib when it has so many mem leaks?
- Date: Thu, 18 Mar 1999 14:32:20 -0700
john@giorgio.hart.bbk.ac.uk wrote:
>
> marc@bowtie.nl
> >the added advantage of having a "normal" view of one's memory consumption
> >should easily outweigh the speed advantage, if there is any at all.
>
> Ok, here's a glib vs malloc/free benchmark. On Solaris 2.6 with Sun cc I get
> glib about 40% faster than malloc/free. It's not a very good benchmark :)
>
> So, glib is faster (on Solaris anyway), and you get no heap fragmentation.
[snip source code]
Instead of testing 'slist' construction, which is mostly what your test
program
is doing, I modified it to create 100 blocks of memory, and then free
them
(to attempt to get a reasonable usage), so that the only difference
between
the two sets of code is just the allocator used. I am also allocating
various
different sizes of memory.
On my system (RedHat 5.2, glib 1.2.0), the glib malloc is faster up to
10
iterations, but then the malloc/free version gets better
./memtest xxx
xxx malloc g_alloc
1 0.000609 0.000463
10 0.003127 0.003097
12 0.003683 0.003678 (Turning point here)
13 0.003926 0.003996
100 0.027999 0.029947
1000 0.277604 0.293464
10000 2.76537 2.93653
which makes me think that the extra complexity is not really benefiting
me on
a RedHat5.2 system. Can someone else try this on other OS's/versions and
see
how it compares?
-----------------------
#include <stdio.h>
#include <gtk/gtk.h>
GTimer *timer = NULL;
int
main( int argc, char **argv )
{
int max = atoi( argv[1] );
int i, j;
void* xlist[100];
timer = g_timer_new();
printf( "Starting with malloc/free ...\n" );
g_timer_reset( timer );
for( j = 0; j < max; j++ ) {
for( i = 0; i < 100; i++ ) {
xlist[i] = (void*)malloc((i % 15) * 4);
}
for( i = 0; i < 100; i++ ) {
free(xlist[i]);
}
}
printf( "... %d nodes in %g secs\n",
max * 100, g_timer_elapsed( timer, NULL ) );
printf( "Starting with g_malloc/g_free ...\n" );
g_timer_reset( timer );
for( j = 0; j < max; j++ ) {
for( i = 0; i < 100; i++ ) {
xlist[i] = g_malloc((i % 15) * 4);
}
for( i = 0; i < 100; i++ ) {
g_free(xlist[i]);
}
}
printf( "... %d nodes in %g secs\n",
max * 100, g_timer_elapsed( timer, NULL ) );
return( 0 );
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]