From efcb42956887dcfef57aed07c43cc55547ffcd32 Mon Sep 17 00:00:00 2001 From: emaste Date: Fri, 23 May 2014 17:46:00 +0000 Subject: [PATCH] MFC r266208: 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%. git-svn-id: svn://svn.freebsd.org/base/stable/10@266590 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- usr.sbin/pmcstat/pmcstat_log.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/usr.sbin/pmcstat/pmcstat_log.c b/usr.sbin/pmcstat/pmcstat_log.c index f0e493959..40de320f1 100644 --- a/usr.sbin/pmcstat/pmcstat_log.c +++ b/usr.sbin/pmcstat/pmcstat_log.c @@ -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); } -- 2.45.0