forked from enlightenment/efl
Add benchmark against glib so we see where we stand.
SVN revision: 35699
This commit is contained in:
parent
5a9be377b1
commit
1d3013e37d
|
@ -9,7 +9,8 @@ AM_CPPFLAGS = \
|
|||
-DPACKAGE_LIB_DIR=\"$(libdir)\" \
|
||||
-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \
|
||||
-DPACKAGE_BUILD_DIR=\"`pwd`/$(top_builddir)\" \
|
||||
@CHECK_CFLAGS@
|
||||
@CHECK_CFLAGS@ \
|
||||
@GLIB_CFLAGS@
|
||||
|
||||
if EINA_HAVE_GLIB
|
||||
|
||||
|
@ -54,7 +55,7 @@ eina_bench_stringshare.c \
|
|||
eina_bench_convert.c \
|
||||
eina_bench_array.c
|
||||
|
||||
eina_bench_LDADD = $(top_builddir)/src/lib/libeina.la
|
||||
eina_bench_LDADD = @GLIB_LIBS@ $(top_builddir)/src/lib/libeina.la
|
||||
|
||||
endif
|
||||
|
||||
|
|
|
@ -25,6 +25,10 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef EINA_BENCH_HAVE_GLIB
|
||||
#include <glib.h>
|
||||
#endif
|
||||
|
||||
#include "eina_bench.h"
|
||||
#include "eina_array.h"
|
||||
#include "eina_list.h"
|
||||
|
@ -424,6 +428,130 @@ eina_bench_inlist_4evas_render_iterator(int request)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef EINA_BENCH_HAVE_GLIB
|
||||
static void
|
||||
eina_bench_glist_4evas_render(int request)
|
||||
{
|
||||
GList *list = NULL;
|
||||
GList *tmp;
|
||||
Eina_Bench_Object *ebo;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
for (i = 0; i < 1000; ++i)
|
||||
{
|
||||
for (j = 0; j < request; ++j)
|
||||
{
|
||||
ebo = malloc(sizeof (Eina_Bench_Object));
|
||||
if (!ebo) continue ;
|
||||
|
||||
ebo->keep = rand() < (RAND_MAX / 2) ? EINA_TRUE : EINA_FALSE;
|
||||
|
||||
list = g_list_prepend(list, ebo);
|
||||
}
|
||||
|
||||
if (i == 500)
|
||||
{
|
||||
while (list)
|
||||
{
|
||||
free(list->data);
|
||||
list = g_list_delete_link(list, list);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i % 30 == 0)
|
||||
{
|
||||
tmp = list;
|
||||
while (tmp)
|
||||
{
|
||||
GList *reminder = tmp;
|
||||
|
||||
ebo = reminder->data;
|
||||
tmp = g_list_next(tmp);
|
||||
|
||||
if (ebo->keep == EINA_FALSE)
|
||||
{
|
||||
list = g_list_delete_link(list, reminder);
|
||||
free(ebo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (tmp = list; tmp; tmp = g_list_next(tmp))
|
||||
{
|
||||
ebo = tmp->data;
|
||||
|
||||
ebo->keep = rand() < (RAND_MAX / 2) ? ebo->keep : EINA_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
while (list)
|
||||
{
|
||||
free(list->data);
|
||||
list = g_list_delete_link(list, list);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
eina_bench_gptrarray_4evas_render(int request)
|
||||
{
|
||||
GPtrArray *array = NULL;
|
||||
Eina_Bench_Object *ebo;
|
||||
unsigned int j;
|
||||
int i;
|
||||
|
||||
array = g_ptr_array_new();
|
||||
|
||||
for (i = 0; i < 1000; ++i)
|
||||
{
|
||||
for (j = 0; j < (unsigned int) request; ++j)
|
||||
{
|
||||
ebo = malloc(sizeof (Eina_Bench_Object));
|
||||
if (!ebo) continue ;
|
||||
|
||||
ebo->keep = rand() < (RAND_MAX / 2) ? EINA_TRUE : EINA_FALSE;
|
||||
|
||||
g_ptr_array_add(array, ebo);
|
||||
}
|
||||
|
||||
if (i == 500)
|
||||
{
|
||||
for (j = 0; j < array->len; ++j)
|
||||
free(g_ptr_array_index(array, j));
|
||||
g_ptr_array_remove_range(array, 0, array->len);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i % 30 == 0)
|
||||
{
|
||||
for (j = 0; j < array->len; )
|
||||
{
|
||||
ebo = g_ptr_array_index(array, j);
|
||||
|
||||
if (ebo->keep == EINA_FALSE)
|
||||
free(g_ptr_array_remove_index_fast(array, j));
|
||||
else
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < array->len; ++j)
|
||||
{
|
||||
ebo = g_ptr_array_index(array, j);
|
||||
|
||||
ebo->keep = rand() < (RAND_MAX / 2) ? ebo->keep : EINA_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < array->len; ++j)
|
||||
free(g_ptr_array_index(array, j));
|
||||
g_ptr_array_free(array, TRUE);
|
||||
}
|
||||
#endif
|
||||
|
||||
void eina_bench_array(Eina_Bench *bench)
|
||||
{
|
||||
eina_bench_register(bench, "array-inline", EINA_BENCH(eina_bench_array_4evas_render_inline), 200, 4000, 100);
|
||||
|
@ -432,5 +560,9 @@ void eina_bench_array(Eina_Bench *bench)
|
|||
eina_bench_register(bench, "list-iterator", EINA_BENCH(eina_bench_list_4evas_render_iterator), 200, 4000, 100);
|
||||
eina_bench_register(bench, "inlist", EINA_BENCH(eina_bench_inlist_4evas_render), 200, 4000, 100);
|
||||
eina_bench_register(bench, "inlist-iterator", EINA_BENCH(eina_bench_inlist_4evas_render_iterator), 200, 4000, 100);
|
||||
#ifdef EINA_BENCH_HAVE_GLIB
|
||||
eina_bench_register(bench, "glist", EINA_BENCH(eina_bench_glist_4evas_render), 200, 4000, 100);
|
||||
eina_bench_register(bench, "gptrarray", EINA_BENCH(eina_bench_gptrarray_4evas_render), 200, 4000, 100);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -16,11 +16,19 @@
|
|||
* if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef EINA_BENCH_HAVE_GLIB
|
||||
#include <glib.h>
|
||||
#endif
|
||||
|
||||
#include "eina_hash.h"
|
||||
#include "eina_array.h"
|
||||
#include "eina_bench.h"
|
||||
|
@ -219,9 +227,57 @@ eina_bench_lookup_djb2_inline(int request)
|
|||
eina_array_free(array);
|
||||
}
|
||||
|
||||
#ifdef EINA_BENCH_HAVE_GLIB
|
||||
typedef struct _Eina_Bench_Glib Eina_Bench_Glib;
|
||||
struct _Eina_Bench_Glib
|
||||
{
|
||||
char *key;
|
||||
int value;
|
||||
};
|
||||
|
||||
static void
|
||||
eina_bench_lookup_ghash(int request)
|
||||
{
|
||||
Eina_Bench_Glib *elm;
|
||||
GHashTable *hash;
|
||||
unsigned int i;
|
||||
|
||||
hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, free);
|
||||
|
||||
for (i = 0; i < (unsigned int) request; ++i)
|
||||
{
|
||||
elm = malloc(sizeof (Eina_Bench_Glib) + 10);
|
||||
if (!elm) continue ;
|
||||
|
||||
elm->key = (char*) (elm + 1);
|
||||
|
||||
snprintf(elm->key, 10, "%i", i);
|
||||
elm->value = i;
|
||||
|
||||
g_hash_table_insert(hash, elm->key, elm);
|
||||
}
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
for (i = 0; i < (unsigned int) request; ++i)
|
||||
{
|
||||
char tmp_key[10];
|
||||
|
||||
snprintf(tmp_key, 10, "%i", rand() % request);
|
||||
|
||||
elm = g_hash_table_lookup(hash, tmp_key);
|
||||
}
|
||||
|
||||
g_hash_table_destroy(hash);
|
||||
}
|
||||
#endif
|
||||
|
||||
void eina_bench_hash(Eina_Bench *bench)
|
||||
{
|
||||
eina_bench_register(bench, "superfast-lookup", EINA_BENCH(eina_bench_lookup_superfast), 1000, 180000, 2500);
|
||||
eina_bench_register(bench, "djb2-lookup", EINA_BENCH(eina_bench_lookup_djb2), 1000, 180000, 2500);
|
||||
eina_bench_register(bench, "djb2-lookup-inline", EINA_BENCH(eina_bench_lookup_djb2_inline), 1000, 180000, 2500);
|
||||
#ifdef EINA_BENCH_HAVE_GLIB
|
||||
eina_bench_register(bench, "ghash-lookup", EINA_BENCH(eina_bench_lookup_ghash), 1000, 180000, 2500);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -16,10 +16,18 @@
|
|||
* if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef EINA_BENCH_HAVE_GLIB
|
||||
#include <glib.h>
|
||||
#endif
|
||||
|
||||
#include "eina_stringshare.h"
|
||||
#include "eina_bench.h"
|
||||
#include "eina_array.h"
|
||||
|
@ -68,7 +76,43 @@ eina_bench_stringshare_job(int request)
|
|||
eina_stringshare_shutdown();
|
||||
}
|
||||
|
||||
#ifdef EINA_BENCH_HAVE_GLIB
|
||||
static void
|
||||
eina_bench_stringchunk_job(int request)
|
||||
{
|
||||
GStringChunk *chunk;
|
||||
unsigned int j;
|
||||
int i;
|
||||
|
||||
chunk = g_string_chunk_new(4096);
|
||||
|
||||
for (i = 0; i < request; ++i)
|
||||
{
|
||||
char build[64];
|
||||
|
||||
snprintf(build, 64, "string_%i", i);
|
||||
g_string_chunk_insert_const(chunk, build);
|
||||
}
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
for (j = 0; j < 200; ++j)
|
||||
for (i = 0; i < request; ++i)
|
||||
{
|
||||
char build[64];
|
||||
|
||||
snprintf(build, 64, "string_%i", rand() % request);
|
||||
g_string_chunk_insert_const(chunk, build);
|
||||
}
|
||||
|
||||
g_string_chunk_free(chunk);
|
||||
}
|
||||
#endif
|
||||
|
||||
void eina_bench_stringshare(Eina_Bench *bench)
|
||||
{
|
||||
eina_bench_register(bench, "stringshare", EINA_BENCH(eina_bench_stringshare_job), 100, 20100, 500);
|
||||
#ifdef EINA_BENCH_HAVE_GLIB
|
||||
eina_bench_register(bench, "stringchunk (glib)", EINA_BENCH(eina_bench_stringchunk_job), 100, 20100, 500);
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue