~amodm/tcprstat/osx

« back to all changes in this revision

Viewing changes to src/stats.c

  • Committer: Ignacio Nin
  • Date: 2010-07-29 19:54:39 UTC
  • Revision ID: git-v1:8436146bdaef9c179dfd084bdacc1f7193deb141
Squares sum

Added new statistic: Squares sum

Show diffs side-by-side

added added

removed removed

Lines of Context:
346
346
}
347
347
 
348
348
unsigned long
 
349
stats_sqs(struct stats_results *results, int percentile) {
 
350
    unsigned long n;
 
351
    unsigned long sqs = 0;
 
352
    unsigned long i;
 
353
    
 
354
    if (!results->statscount)
 
355
        return 0;
 
356
 
 
357
    if (percentile == 0 || percentile == 100)
 
358
        n = results->statscount;
 
359
    else {
 
360
        if (!results->sorted)
 
361
            sort_results(results);
 
362
        
 
363
        n = (results->statscount * percentile ) / 100;
 
364
        
 
365
    }
 
366
    
 
367
    if (!n)
 
368
        return 0;
 
369
    
 
370
    for (i = 0; i < n; i ++)
 
371
        sqs += results->stats[i] * results->stats[i];
 
372
    
 
373
    return sqs;
 
374
    
 
375
}
 
376
 
 
377
unsigned long
349
378
stats_min(struct stats_results *results, int percentile) {
350
379
    if (!results->statscount)
351
380
        return 0;