зеркало из https://github.com/mozilla/pjs.git
[not part of build] Increased number of downloads/reads to 50, added median().
This commit is contained in:
Родитель
98bc4c37ef
Коммит
fad4f5ce4f
|
@ -123,27 +123,61 @@ function test()
|
||||||
print("disk cache metadata broken!");
|
print("disk cache metadata broken!");
|
||||||
}
|
}
|
||||||
|
|
||||||
function time()
|
function median(array)
|
||||||
{
|
{
|
||||||
var System = java.lang.System;
|
var cmp = function(x, y) { return x - y; }
|
||||||
var url = new java.net.URL("http://www.mozilla.org");
|
array.sort(cmp);
|
||||||
var begin = System.currentTimeMillis();
|
var middle = Math.floor(array.length / 2);
|
||||||
for (var i = 0; i < 5; ++i)
|
return array[middle];
|
||||||
download(url);
|
|
||||||
var end = System.currentTimeMillis();
|
|
||||||
print("5 downloads took " + (end - begin) + " milliseconds.");
|
|
||||||
print("average = " + ((end - begin) / 5) + " milliseconds.");
|
|
||||||
|
|
||||||
begin = System.currentTimeMillis();
|
|
||||||
for (var i = 0; i < 5; ++i)
|
|
||||||
read(url);
|
|
||||||
end = System.currentTimeMillis();
|
|
||||||
print("5 reads took " + (end - begin) + " milliseconds.");
|
|
||||||
print("average = " + ((end - begin) / 5) + " milliseconds.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sum(array)
|
||||||
|
{
|
||||||
|
var s = 0;
|
||||||
|
var len = array.length;
|
||||||
|
for (var i = 0; i < len; ++i)
|
||||||
|
s += array[i];
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
function time()
|
||||||
|
{
|
||||||
|
var N = 50;
|
||||||
|
var System = java.lang.System;
|
||||||
|
var url = new java.net.URL("http://www.mozilla.org");
|
||||||
|
var downloadTimes = new Array();
|
||||||
|
for (var i = 0; i < N; ++i) {
|
||||||
|
var begin = System.currentTimeMillis();
|
||||||
|
download(url);
|
||||||
|
var end = System.currentTimeMillis();
|
||||||
|
downloadTimes.push(end - begin);
|
||||||
|
}
|
||||||
|
var downloadTotal = sum(downloadTimes);
|
||||||
|
var downloadMean = downloadTotal / N;
|
||||||
|
var downloadMedian = median(downloadTimes);
|
||||||
|
print("" + N + " downloads took " + downloadTotal + " milliseconds.");
|
||||||
|
print("mean = " + downloadMean + " milliseconds.");
|
||||||
|
print("median = " + downloadMedian + " milliseconds.");
|
||||||
|
|
||||||
|
var readTimes = new Array();
|
||||||
|
for (var i = 0; i < N; ++i) {
|
||||||
|
var begin = System.currentTimeMillis();
|
||||||
|
read(url);
|
||||||
|
var end = System.currentTimeMillis();
|
||||||
|
readTimes.push(end - begin);
|
||||||
|
}
|
||||||
|
var readTotal = sum(readTimes);
|
||||||
|
var readMean = readTotal / N;
|
||||||
|
var readMedian = median(readTimes);
|
||||||
|
print("" + N + " reads took " + readTotal + " milliseconds.");
|
||||||
|
print("mean = " + readMean + " milliseconds.");
|
||||||
|
print("median = " + readMedian + " milliseconds.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// load the cache service before doing anything with Java...
|
||||||
|
getCacheService();
|
||||||
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
getCacheService();
|
|
||||||
print("cache service loaded.");
|
print("cache service loaded.");
|
||||||
} else {
|
} else {
|
||||||
print("running disk cache test.");
|
print("running disk cache test.");
|
||||||
|
|
Загрузка…
Ссылка в новой задаче