Skip to content

Commit

Permalink
am 6b896be: am b0ba985: Add standard deviation to the test results
Browse files Browse the repository at this point in the history
Merge commit '6b896be7a60e0c0021e903f8560c838d4e334271'

* commit '6b896be7a60e0c0021e903f8560c838d4e334271':
  Add standard deviation to the test results
  • Loading branch information
Xia Wang authored and Android Git Automerger committed Nov 24, 2009
2 parents 50752df + 6b896be commit 7d33939
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
20 changes: 15 additions & 5 deletions tests/sdcard/stopwatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <stdio.h>
#include <time.h>
#include "stopwatch.h"
#include <math.h>

#define SNPRINTF_OR_RETURN(str, size, format, ...) { \
int len = snprintf((str), (size), (format), ## __VA_ARGS__); \
Expand All @@ -53,7 +54,7 @@ namespace android_test {
StopWatch::StopWatch(const char *name, size_t capacity)
: mName(strdup(name)), mNum(0), mData(NULL), mDataLen(0), mCapacity(capacity * 2),
mSizeKbytes(0), mAlreadyPrinted(false), mPrintRaw(false),
mDuration(0.0),
mDuration(0.0), mDeviation(0.0),
mMinDuration(0.0), mMinIdx(0),
mMaxDuration(0.0), mMaxIdx(0),
mDeltas(NULL), mUsed(false)
Expand Down Expand Up @@ -126,7 +127,7 @@ void StopWatch::sprint(char **str, size_t *size)
{
// print comment header and summary values.

SNPRINTF_OR_RETURN(*str, *size, "# Name Iterations Duration Min MinIdx Max MaxIdx SizeMbytes\n");
SNPRINTF_OR_RETURN(*str, *size, "# Name Iterations Duration Min MinIdx Max MaxIdx SizeKbytes\n");
SNPRINTF_OR_RETURN(*str, *size, "%s %d %f %f %d %f %d %d\n", mName, mNum, mDuration,
mMinDuration, mMinIdx, mMaxDuration, mMaxIdx, mSizeKbytes);
// print each duration sample
Expand Down Expand Up @@ -164,8 +165,8 @@ void StopWatch::checkCapacity()
void StopWatch::processSamples()
{
if (kVerbose) fprintf(stderr, "processing samples\n");
mDeltas= new double[mDataLen / 2];

size_t n = mDataLen / 2;
mDeltas= new double[n];
for (size_t i = 0; i < mDataLen; i += 2) // even: start odd: stop
{
long second = mData[i + 1].mTime.tv_sec - mData[i].mTime.tv_sec;
Expand All @@ -174,7 +175,7 @@ void StopWatch::processSamples()
mDeltas[i / 2] = double(second) + double(nano) / 1.0e9;
}

for (size_t i = 0; i < mDataLen / 2; ++i)
for (size_t i = 0; i < n; ++i)
{
if (0 == i)
{
Expand All @@ -195,8 +196,16 @@ void StopWatch::processSamples()
}
mDuration += mDeltas[i];
}
double avgDuration = mDuration / n;
double diffSQ = 0.0;
for (size_t i = 0; i < n; ++i)
{
diffSQ += pow((mDeltas[i] - avgDuration), 2.0);
}
mDeviation = sqrt(diffSQ / n);
}


double StopWatch::timespecToDouble(const struct timespec& time)
{
double val = double(time.tv_nsec) / 1.0e9 + double(time.tv_sec);
Expand All @@ -210,6 +219,7 @@ void StopWatch::printAverageMinMax(char **str, size_t *size)
if (mDataLen > 2) // if there is only one sample, avg, min, max are trivial.
{
SNPRINTF_OR_RETURN(*str, *size, "# Average %s duration %f s/op\n", mName, mDuration / mNum);
SNPRINTF_OR_RETURN(*str, *size, "# Standard deviation %s duration %f \n", mName, mDeviation);
SNPRINTF_OR_RETURN(*str, *size, "# Min %s duration %f [%d]\n", mName, mMinDuration, mMinIdx);
SNPRINTF_OR_RETURN(*str, *size, "# Max %s duration %f [%d]\n", mName, mMaxDuration, mMaxIdx);
}
Expand Down
1 change: 1 addition & 0 deletions tests/sdcard/stopwatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class StopWatch {
bool mPrintRaw;

double mDuration;
double mDeviation;
double mMinDuration;
size_t mMinIdx;
double mMaxDuration;
Expand Down

0 comments on commit 7d33939

Please sign in to comment.