benchmark hashfind

This commit is contained in:
Lucas De Marchi 2013-09-25 02:07:47 -03:00
parent f758b1f92a
commit d7ac0805bd
1 changed files with 16 additions and 29 deletions

View File

@ -295,7 +295,7 @@ static _always_inline_ unsigned int hashfunc(const char *key, unsigned int len)
* none of key or value are copied, just references are remembered as is, * none of key or value are copied, just references are remembered as is,
* make sure they are live while pair exists in hash! * make sure they are live while pair exists in hash!
*/ */
static _always_inline_ int _hash_add(struct hash *hash, const char *key, const void *value) int hash_add(struct hash *hash, const char *key, const void *value)
{ {
unsigned int keylen = strlen(key); unsigned int keylen = strlen(key);
unsigned int hashval = hashfunc(key, keylen); unsigned int hashval = hashfunc(key, keylen);
@ -332,19 +332,6 @@ static _always_inline_ int _hash_add(struct hash *hash, const char *key, const v
return 0; return 0;
} }
int hash_add(struct hash *hash, const char *key, const void *value)
{
unsigned long t;
int ret;
t = get_cycles(0);
ret = _hash_add(hash, key, value);
t = get_cycles(t);
printf("%lu %lu\n", strlen(key), t);
return ret;
}
#if 0 #if 0
void hash_dump(struct hash *hash) void hash_dump(struct hash *hash)
{ {
@ -382,7 +369,7 @@ void hash_dump_keys(struct hash *hash) {}
#endif #endif
/* similar to hash_add(), but fails if key already exists */ /* similar to hash_add(), but fails if key already exists */
static _always_inline_ int _hash_add_unique(struct hash *hash, const char *key, const void *value) int hash_add_unique(struct hash *hash, const char *key, const void *value)
{ {
unsigned int keylen = strlen(key); unsigned int keylen = strlen(key);
unsigned int hashval = hashfunc(key, keylen); unsigned int hashval = hashfunc(key, keylen);
@ -415,20 +402,7 @@ static _always_inline_ int _hash_add_unique(struct hash *hash, const char *key,
return 0; return 0;
} }
int hash_add_unique(struct hash *hash, const char *key, const void *value) static _always_inline_ void *_hash_find(const struct hash *hash, const char *key)
{
unsigned long t;
int ret;
t = get_cycles(0);
ret = _hash_add_unique(hash, key, value);
t = get_cycles(t);
printf("%lu %lu\n", strlen(key), t);
return ret;
}
void *hash_find(const struct hash *hash, const char *key)
{ {
unsigned int keylen = strlen(key); unsigned int keylen = strlen(key);
unsigned int hashval = hashfunc(key, keylen); unsigned int hashval = hashfunc(key, keylen);
@ -446,6 +420,19 @@ void *hash_find(const struct hash *hash, const char *key)
return NULL; return NULL;
} }
void *hash_find(const struct hash *hash, const char *key)
{
unsigned long t;
void *ret;
t = get_cycles(0);
ret = _hash_find(hash, key);
t = get_cycles(t);
printf("%lu %lu\n", strlen(key), t);
return ret;
}
int hash_del(struct hash *hash, const char *key) int hash_del(struct hash *hash, const char *key)
{ {
unsigned int keylen = strlen(key); unsigned int keylen = strlen(key);