зеркало из https://github.com/mozilla/gecko-dev.git
Separate tests for reading and writing.
This commit is contained in:
Родитель
56736e0108
Коммит
cec42466c4
|
@ -1,13 +1,26 @@
|
||||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
Subject:
|
*
|
||||||
Date:
|
* The contents of this file are subject to the Mozilla Public
|
||||||
Thu, 11 Jan 2001 16:38:10 -0800
|
* License Version 1.1 (the "License"); you may not use this file
|
||||||
From:
|
* except in compliance with the License. You may obtain a copy of
|
||||||
Doug Turner <dougt@z.netscape.com>
|
* the License at http://www.mozilla.org/MPL/
|
||||||
To:
|
*
|
||||||
gordon@netscape.com
|
* 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.
|
||||||
|
*
|
||||||
|
* The Original Code is nsCacheManager.h, released January 22, 2001.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Netscape Communications
|
||||||
|
* Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||||
|
* Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
* Doug Turner
|
||||||
|
* Gordon Sheridan
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "nscore.h"
|
#include "nscore.h"
|
||||||
|
@ -15,18 +28,13 @@ Subject:
|
||||||
#include "mcom_db.h"
|
#include "mcom_db.h"
|
||||||
#include "nsString.h"
|
#include "nsString.h"
|
||||||
|
|
||||||
DB* myDB;
|
|
||||||
|
|
||||||
#define DATASIZE 512
|
#define DATASIZE 512
|
||||||
#define ENTRYCOUNT 512
|
#define ENTRYCOUNT 512
|
||||||
#define USE_ENTRY_ID 1
|
#define USE_ENTRY_ID 1
|
||||||
|
#define EXTRA_LOOKUP 1
|
||||||
|
|
||||||
int
|
DB* myDB;
|
||||||
testDBM(int cycles)
|
HASHINFO hash_info = {
|
||||||
{
|
|
||||||
|
|
||||||
// create database file
|
|
||||||
HASHINFO hash_info = {
|
|
||||||
16*1024 , /* bucket size */
|
16*1024 , /* bucket size */
|
||||||
0 , /* fill factor */
|
0 , /* fill factor */
|
||||||
0 , /* number of elements */
|
0 , /* number of elements */
|
||||||
|
@ -35,6 +43,15 @@ testDBM(int cycles)
|
||||||
0} ; /* byte order */
|
0} ; /* byte order */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int writeDBM(int cycles)
|
||||||
|
{
|
||||||
|
DBT db_key, db_data ;
|
||||||
|
PRIntervalTime time = PR_IntervalNow();
|
||||||
|
|
||||||
|
while (cycles--) {
|
||||||
|
// create database file
|
||||||
myDB = dbopen("/tmp/foodb",
|
myDB = dbopen("/tmp/foodb",
|
||||||
O_RDWR | O_CREAT ,
|
O_RDWR | O_CREAT ,
|
||||||
0600 ,
|
0600 ,
|
||||||
|
@ -51,11 +68,6 @@ testDBM(int cycles)
|
||||||
char * data = (char*) malloc(DATASIZE);
|
char * data = (char*) malloc(DATASIZE);
|
||||||
for (x=0; x<DATASIZE; x++)
|
for (x=0; x<DATASIZE; x++)
|
||||||
*data = '\0';
|
*data = '\0';
|
||||||
|
|
||||||
|
|
||||||
// write key-data pairs to database
|
|
||||||
DBT db_key, db_data ;
|
|
||||||
|
|
||||||
for (x=1; x<=ENTRYCOUNT; x++) {
|
for (x=1; x<=ENTRYCOUNT; x++) {
|
||||||
nsCAutoString keyName("foo");
|
nsCAutoString keyName("foo");
|
||||||
keyName.AppendInt( x );
|
keyName.AppendInt( x );
|
||||||
|
@ -85,13 +97,21 @@ testDBM(int cycles)
|
||||||
|
|
||||||
(*myDB->sync)(myDB, 0);
|
(*myDB->sync)(myDB, 0);
|
||||||
free(data);
|
free(data);
|
||||||
|
}
|
||||||
|
return PR_IntervalToMilliseconds( PR_IntervalNow() - time);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
readDBM(int cycles)
|
||||||
|
{
|
||||||
// begin timing "lookups"
|
// begin timing "lookups"
|
||||||
int status = 0 ;
|
int status = 0 ;
|
||||||
|
DBT db_key, db_data ;
|
||||||
PRIntervalTime time = PR_IntervalNow();
|
PRIntervalTime time = PR_IntervalNow();
|
||||||
|
|
||||||
while (cycles--) {
|
while (cycles--) {
|
||||||
for (x=1; x<=ENTRYCOUNT; x++) {
|
for (int x=1; x<=ENTRYCOUNT; x++) {
|
||||||
#if USE_ENTRY_ID
|
#if USE_ENTRY_ID
|
||||||
DBT entry_data;
|
DBT entry_data;
|
||||||
|
|
||||||
|
@ -116,6 +136,17 @@ testDBM(int cycles)
|
||||||
printf("Bad Status %d\n", status);
|
printf("Bad Status %d\n", status);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#if EXTRA_LOOKUP
|
||||||
|
db_key.data = (void*)&x;
|
||||||
|
db_key.size = sizeof(x);
|
||||||
|
|
||||||
|
status = (*myDB->get)(myDB, &db_key, &entry_data, 0);
|
||||||
|
if(status != 0) {
|
||||||
|
printf("Bad Status %d\n", status);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(*myDB->sync)(myDB, 0);
|
(*myDB->sync)(myDB, 0);
|
||||||
|
@ -126,7 +157,7 @@ testDBM(int cycles)
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
testFile(int cycles)
|
writeFile(int cycles)
|
||||||
{
|
{
|
||||||
FILE* file;
|
FILE* file;
|
||||||
int fStatus;
|
int fStatus;
|
||||||
|
@ -135,6 +166,8 @@ testFile(int cycles)
|
||||||
for (x=0; x<DATASIZE; x++)
|
for (x=0; x<DATASIZE; x++)
|
||||||
*data = '\0';
|
*data = '\0';
|
||||||
|
|
||||||
|
PRIntervalTime time = PR_IntervalNow();
|
||||||
|
while (cycles--) {
|
||||||
// create "cache" directories
|
// create "cache" directories
|
||||||
mkdir("/tmp/foo", 0755);
|
mkdir("/tmp/foo", 0755);
|
||||||
|
|
||||||
|
@ -162,11 +195,21 @@ testFile(int cycles)
|
||||||
}
|
}
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return PR_IntervalToMilliseconds( PR_IntervalNow() - time);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
readFile(int cycles)
|
||||||
|
{
|
||||||
|
FILE* file;
|
||||||
|
int fStatus;
|
||||||
|
|
||||||
// begin timing "lookups"
|
// begin timing "lookups"
|
||||||
PRIntervalTime time = PR_IntervalNow();
|
PRIntervalTime time = PR_IntervalNow();
|
||||||
while (cycles--) {
|
while (cycles--) {
|
||||||
for (x=1; x<=ENTRYCOUNT; x++) {
|
for (int x=1; x<=ENTRYCOUNT; x++) {
|
||||||
nsCAutoString filename; filename.Assign("/tmp/foo/");
|
nsCAutoString filename; filename.Assign("/tmp/foo/");
|
||||||
filename.AppendInt( x % 32 );
|
filename.AppendInt( x % 32 );
|
||||||
filename.Append("/");
|
filename.Append("/");
|
||||||
|
@ -194,13 +237,22 @@ testFile(int cycles)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
int
|
||||||
main(void)
|
main(void)
|
||||||
{
|
{
|
||||||
int totalDBMTime = testDBM(32);
|
int totalDBMTime = writeDBM(32);
|
||||||
int totalFileTime = testFile(32);
|
int totalFileTime = writeFile(32);
|
||||||
|
|
||||||
printf("total dbm IO ---- > (%d) milliseconds\n", totalDBMTime);
|
printf("total write dbm IO ---- > (%d) milliseconds\n", totalDBMTime);
|
||||||
printf("total file IO ---- > (%d) milliseconds\n", totalFileTime);
|
printf("total write file IO ---- > (%d) milliseconds\n", totalFileTime);
|
||||||
|
|
||||||
|
totalDBMTime = readDBM(32);
|
||||||
|
totalFileTime = readFile(32);
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
printf("total read dbm IO ---- > (%d) milliseconds\n", totalDBMTime);
|
||||||
|
printf("total read file IO ---- > (%d) milliseconds\n", totalFileTime);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче