Speed up pmcstat by improving string hash

In one case generating callgraph output from a 24MB system-wide sampling
data file took 17.4 seconds on average.  Profiling showed pmcstat
spending a lot of time in strcmp, due to hash collisions.

Replacing the XOR-only hash with FNV-1a reduces the run time for my
test by 40%.
This commit is contained in:
Ed Maste 2014-05-16 03:05:53 +00:00
parent 06e36338ca
commit dc17b1feaa

View File

@ -307,10 +307,10 @@ pmcstat_stats_reset(int reset_global)
static int
pmcstat_string_compute_hash(const char *s)
{
int hash;
unsigned hash;
for (hash = 0; *s; s++)
hash ^= *s;
for (hash = 2166136261; *s; s++)
hash = (hash ^ *s) * 16777619;
return (hash & PMCSTAT_HASH_MASK);
}