2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 22:01:16 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2000-02-03 01:59:15 +00:00
|
|
|
*
|
2004-04-18 22:01:16 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2000-02-03 01:59:15 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
2000-02-03 01:59:15 +00:00
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 22:01:16 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-28 20:14:13 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2000-02-03 01:59:15 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 22:01:16 +00:00
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
2001-09-28 20:14:13 +00:00
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 22:01:16 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-28 20:14:13 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 22:01:16 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2000-02-03 01:59:15 +00:00
|
|
|
|
|
|
|
#include "prio.h"
|
|
|
|
#include "prinrval.h"
|
|
|
|
#include "prmem.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
void
|
|
|
|
NS_MeanAndStdDev(double n, double sumOfValues, double sumOfSquaredValues,
|
|
|
|
double *meanResult, double *stdDevResult)
|
|
|
|
{
|
|
|
|
double mean = 0.0, var = 0.0, stdDev = 0.0;
|
|
|
|
if (n > 0.0 && sumOfValues >= 0) {
|
|
|
|
mean = sumOfValues / n;
|
|
|
|
double temp = (n * sumOfSquaredValues) - (sumOfValues * sumOfValues);
|
|
|
|
if (temp < 0.0 || n <= 1)
|
|
|
|
var = 0.0;
|
|
|
|
else
|
|
|
|
var = temp / (n * (n - 1));
|
|
|
|
// for some reason, Windows says sqrt(0.0) is "-1.#J" (?!) so do this:
|
|
|
|
stdDev = var != 0.0 ? sqrt(var) : 0.0;
|
|
|
|
}
|
|
|
|
*meanResult = mean;
|
|
|
|
*stdDevResult = stdDev;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-02-04 07:31:43 +00:00
|
|
|
Test(const char* filename, PRInt32 minSize, PRInt32 maxSize,
|
|
|
|
PRInt32 sizeIncrement, PRInt32 iterations)
|
2000-02-03 01:59:15 +00:00
|
|
|
{
|
|
|
|
fprintf(stdout, " size write: mean stddev iters total: mean stddev iters\n");
|
2000-02-04 07:31:43 +00:00
|
|
|
for (PRInt32 size = minSize; size <= maxSize; size += sizeIncrement) {
|
2000-02-03 01:59:15 +00:00
|
|
|
// create a buffer of stuff to write
|
|
|
|
char* buf = (char*)PR_Malloc(size);
|
|
|
|
if (buf == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
// initialize it with a pattern
|
|
|
|
PRInt32 i;
|
|
|
|
char hex[] = "0123456789ABCDEF";
|
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
buf[i] = hex[i & 0xF];
|
|
|
|
}
|
|
|
|
|
|
|
|
double writeCount = 0, writeRate = 0, writeRateSquared = 0;
|
|
|
|
double totalCount = 0, totalRate = 0, totalRateSquared = 0;
|
2000-02-04 07:31:43 +00:00
|
|
|
for (i = 0; i < iterations; i++) {
|
2000-02-03 01:59:15 +00:00
|
|
|
PRIntervalTime start = PR_IntervalNow();
|
|
|
|
|
2000-02-04 07:31:43 +00:00
|
|
|
char name[1024];
|
|
|
|
sprintf(name, "%s_%d", filename, i);
|
|
|
|
PRFileDesc* fd = PR_Open(name, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0664);
|
2000-02-03 01:59:15 +00:00
|
|
|
if (fd == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
PRIntervalTime writeStart = PR_IntervalNow();
|
|
|
|
PRInt32 rv = PR_Write(fd, buf, size);
|
|
|
|
if (rv < 0) return rv;
|
|
|
|
if (rv != size) return -1;
|
|
|
|
PRIntervalTime writeStop = PR_IntervalNow();
|
|
|
|
|
|
|
|
PRStatus st = PR_Close(fd);
|
|
|
|
if (st == PR_FAILURE) return -1;
|
|
|
|
|
|
|
|
PRIntervalTime stop = PR_IntervalNow();
|
|
|
|
|
|
|
|
PRIntervalTime writeTime = PR_IntervalToMilliseconds(writeStop - writeStart);
|
|
|
|
if (writeTime > 0) {
|
|
|
|
double wr = size / writeTime;
|
|
|
|
writeRate += wr;
|
|
|
|
writeRateSquared += wr * wr;
|
|
|
|
writeCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIntervalTime totalTime = PR_IntervalToMilliseconds(stop - start);
|
|
|
|
if (totalTime > 0) {
|
|
|
|
double t = size / totalTime;
|
|
|
|
totalRate += t;
|
|
|
|
totalRateSquared += t * t;
|
|
|
|
totalCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_Free(buf);
|
|
|
|
|
|
|
|
double writeMean, writeStddev;
|
|
|
|
double totalMean, totalStddev;
|
|
|
|
NS_MeanAndStdDev(writeCount, writeRate, writeRateSquared,
|
|
|
|
&writeMean, &writeStddev);
|
|
|
|
NS_MeanAndStdDev(totalCount, totalRate, totalRateSquared,
|
|
|
|
&totalMean, &totalStddev);
|
|
|
|
fprintf(stdout, "%10d %10.2f %10.2f %10d %10.2f %10.2f %10d\n",
|
|
|
|
size, writeMean, writeStddev, (PRInt32)writeCount,
|
|
|
|
totalMean, totalStddev, (PRInt32)totalCount);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-02-04 07:31:43 +00:00
|
|
|
int
|
|
|
|
main(int argc, char* argv[])
|
2000-02-03 01:59:15 +00:00
|
|
|
{
|
2000-02-04 07:31:43 +00:00
|
|
|
if (argc != 5) {
|
|
|
|
printf("usage: %s <min buf size (K)> <max buf size (K)> <size increment (K)> <iterations>\n", argv[0]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
Test("y:\\foo",
|
|
|
|
atoi(argv[1]) * 1024,
|
|
|
|
atoi(argv[2]) * 1024,
|
|
|
|
atoi(argv[3]) * 1024,
|
|
|
|
atoi(argv[4]));
|
|
|
|
return 0;
|
2000-02-03 01:59:15 +00:00
|
|
|
}
|