GMemChunk performance
- From: tom <tom dbservice com>
- To: gtk-list gnome org
- Subject: GMemChunk performance
- Date: Wed, 15 Jan 2003 16:55:21 +0100
i created a simple program which tests GMemChunk performance...
if i use G_ALLOC_ONLY, i get a very good performance at both allocating
and freeing mem chunks
in this case 'created: ~12500 ms', 'freed: ~6000ms'
if i use G_ALLOC_AND_FREE, i get in the first run:
'created: ~14000 ms', 'freed: ~320000ms'
and in the other runs:
'created: ~270000 ms', 'freed: ~220000ms'
why is the speed in the first run so much better in allocating (about 20
times faster) and so much slower in freeing (about 1.5 times)
and why is G_ALLOC_ONLY so much better then G_ALLOC_AND_FREE
if i look at the results, i would never use G_ALLOC_AND_FREE in a
programm...
i made this test program because i tested the gobject performance
(played a bit with n_preallocs, see at the gtk-devel-list)
and in gtype.c i see that gobject uses G_ALLOC_AND_FREE...
so this explains the bad performance in gobject-2.0
file main.c:
#include <glib.h>
typedef struct test_s test_t;
struct test_s
{
guint8 nothing[1000];
};
#define NUM 100000
#define RUNS 10
int
main (int argc, char *argv[])
{
int i, j;
GTimer *timer;
gulong ms;
GMemChunk *mem;
test_t *chunks[NUM];
mem = g_mem_chunk_new ("test", sizeof (test_t), NUM * sizeof (test_t),
G_ALLOC_ONLY);
//mem = g_mem_chunk_new ("test", sizeof (test_t), NUM * sizeof
(test_t), G_ALLOC_AND_FREE);
timer = g_timer_new ();
g_timer_reset (timer);
for (j = 0; j < RUNS; j++)
{
g_print ("\nrun %i\n", j);
for (i = 0; i < NUM; i++)
{
chunks[i] = g_mem_chunk_alloc (mem);
}
g_timer_elapsed (timer, &ms);
g_print ("created: %i\n", ms);
g_timer_reset (timer);
for (i = 0; i < NUM; i++)
{
g_mem_chunk_free (mem, chunks[i]);
}
g_timer_elapsed (timer, &ms);
g_print ("freed: %i\n", ms);
}
g_mem_chunk_destroy (mem);
g_timer_destroy(timer);
return (0);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]