/* ********************************************************************** * Copyright (c) 2011-2012,International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** */ #include "unicode/utimer.h" #include #include #include #include "sieve.h" /* prime number sieve */ U_CAPI double uprv_calcSieveTime() { #if 1 #define SIEVE_SIZE U_LOTS_OF_TIMES /* standardized size */ #else #define SIEVE_SIZE #endif #define SIEVE_PRINT 0 char sieve[SIEVE_SIZE]; UTimer a,b; int i,k; utimer_getTime(&a); for(int j=0;j0) { k=0; for(i=2;i=n) ce=n; if(fl==ce) { return times[(int)fl]; } else { return (times[(int)fl]+times[(int)ce])/2; } } double medianof(double *times, int n, int type) { switch(type) { case 1: return midpoint(times,n/4,n); case 2: return midpoint(times,n/2,n); case 3: return midpoint(times,(n/2)+(n/4),n); } return -1; } double qs(double *times, int n, double *q1, double *q2, double *q3) { *q1 = medianof(times,n,1); *q2 = medianof(times,n,2); *q3 = medianof(times,n,3); return *q3-*q1; } U_CAPI double uprv_getMeanTime(double *times, uint32_t *timeCount, double *marginOfError) { double q1,q2,q3; int n = *timeCount; /* calculate medians */ qsort(times,n,sizeof(times[0]),comdoub); double iqr = qs(times,n,&q1,&q2,&q3); double rangeMin= (q1-(1.5*iqr)); double rangeMax = (q3+(1.5*iqr)); /* Throw out outliers */ int newN = n; #if U_DEBUG printf("iqr: %.9f, q1=%.9f, q2=%.9f, q3=%.9f, max=%.9f, n=%d\n", iqr,q1,q2,q3,(double)-1, n); #endif for(int i=0;irangeMax) { #if U_DEBUG printf("Removing outlier: %.9f outside [%.9f:%.9f]\n", times[i], rangeMin, rangeMax); #endif times[i--] = times[--newN]; // bring down a new value } } #if U_DEBUG UBool didRemove = false; #endif /* if we removed any outliers, recalculate iqr */ if(newNtimes[i]) minTime=times[i]; if(maxTime