Fix old stddev calc bug (#ifdef'd code, not part of build).

This commit is contained in:
brendan%mozilla.org 2000-05-20 18:41:13 +00:00
Родитель a1285d663d
Коммит 31e48aabc5
1 изменённых файлов: 13 добавлений и 7 удалений

Просмотреть файл

@ -393,12 +393,12 @@ out:
JS_PUBLIC_API(void) JS_PUBLIC_API(void)
JS_HashTableDumpMeter(JSHashTable *ht, JSHashEnumerator dump, FILE *fp) JS_HashTableDumpMeter(JSHashTable *ht, JSHashEnumerator dump, FILE *fp)
{ {
double mean, variance; double sqsum, mean, variance, sigma;
uint32 nchains, nbuckets; uint32 nchains, nbuckets, nentries;
uint32 i, n, maxChain, maxChainLen; uint32 i, n, maxChain, maxChainLen;
JSHashEntry *he; JSHashEntry *he;
variance = 0; sqsum = 0;
nchains = 0; nchains = 0;
maxChainLen = 0; maxChainLen = 0;
nbuckets = NBUCKETS(ht); nbuckets = NBUCKETS(ht);
@ -409,14 +409,20 @@ JS_HashTableDumpMeter(JSHashTable *ht, JSHashEnumerator dump, FILE *fp)
nchains++; nchains++;
for (n = 0; he; he = he->next) for (n = 0; he; he = he->next)
n++; n++;
variance += n * n; sqsum += n * n;
if (n > maxChainLen) { if (n > maxChainLen) {
maxChainLen = n; maxChainLen = n;
maxChain = i; maxChain = i;
} }
} }
mean = (double)ht->nentries / nchains; nentries = ht->nentries;
variance = fabs(variance / nchains - mean * mean); mean = (double)nentries / nchains;
variance = nchains * sqsum - nentries * nentries;
if (variance < 0 || nchains == 1)
variance = 0;
else
variance /= nchains * (nchains - 1);
sigma = sqrt(variance);
fprintf(fp, "\nHash table statistics:\n"); fprintf(fp, "\nHash table statistics:\n");
fprintf(fp, " number of lookups: %u\n", ht->nlookups); fprintf(fp, " number of lookups: %u\n", ht->nlookups);
@ -426,7 +432,7 @@ JS_HashTableDumpMeter(JSHashTable *ht, JSHashEnumerator dump, FILE *fp)
fprintf(fp, " mean steps per hash: %g\n", (double)ht->nsteps fprintf(fp, " mean steps per hash: %g\n", (double)ht->nsteps
/ ht->nlookups); / ht->nlookups);
fprintf(fp, "mean hash chain length: %g\n", mean); fprintf(fp, "mean hash chain length: %g\n", mean);
fprintf(fp, " standard deviation: %g\n", sqrt(variance)); fprintf(fp, " standard deviation: %g\n", sigma);
fprintf(fp, " max hash chain length: %u\n", maxChainLen); fprintf(fp, " max hash chain length: %u\n", maxChainLen);
fprintf(fp, " max hash chain: [%u]\n", maxChain); fprintf(fp, " max hash chain: [%u]\n", maxChain);