X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/b04fe171f0375ecd5d8a24747ca1dff85720a0ca..6b200bc335dc93c5516ccb52f14bd896d8c7fad7:/SecurityTests/cspxutils/utilLib/cputime.c?ds=inline diff --git a/SecurityTests/cspxutils/utilLib/cputime.c b/SecurityTests/cspxutils/utilLib/cputime.c deleted file mode 100644 index 0238f048..00000000 --- a/SecurityTests/cspxutils/utilLib/cputime.c +++ /dev/null @@ -1,81 +0,0 @@ -#include -#include -#include -#include -#include "cputime.h" - -/* - * This returns the frequency of the TBR in cycles per second. - */ -static double GetTBRFreq(void) { - mach_timebase_info_data_t tinfo; - mach_timebase_info(&tinfo); - - double machRatio = (double)tinfo.numer / (double)tinfo.denom; - return machRatio; -} - -/* - * Return TBR Frequency, getting it lazily once. May not be thread safe. - */ -static double TbrFreqLocal = 0.0; // ration for NANOSECONDS -static double tbrFreq() -{ - if(TbrFreqLocal == 0.0) { - TbrFreqLocal = GetTBRFreq(); - printf("machRatio %e\n", TbrFreqLocal); - } - return TbrFreqLocal; -} - -// seconds -double CPUTimeDeltaSec(CPUTime from, CPUTime to) -{ - CPUTime delta = to - from; - return (double)delta * (tbrFreq() * (double)1e-9); -} - -// milliseconds -double CPUTimeDeltaMs(CPUTime from, CPUTime to) -{ - CPUTime delta = to - from; - return (double)delta * (tbrFreq() * (double)1e-6); -} - -// microseconds -double CPUTimeDeltaUs(CPUTime from, CPUTime to) -{ - CPUTime delta = to - from; - return (double)delta * (tbrFreq() * (double)1e-3); -} - -/* - * Calculate the average of an array of doubles. The lowest and highest values - * are discarded if there are more than two samples. Typically used to get an - * average of a set of values returned from CPUTimeDelta*(). - */ -double CPUTimeAvg( - const double *array, - unsigned arraySize) -{ - double sum = 0; - double lowest = array[0]; - double highest = array[0]; - - for(unsigned dex=0; dex highest) { - highest = curr; - } - } - if(arraySize > 2) { - sum -= lowest; - sum -= highest; - arraySize -= 2; - } - return sum / (double)arraySize; -}