31 var
SB_NS =
"http://songbirdnest.com/data/1.0#";
34 var
dbe =
Cc[
"@songbirdnest.com/Songbird/DatabaseEngine;1"]
35 .getService(
Ci.sbIDatabaseEngine);
37 dbe.localeCollationEnabled =
true;
42 var environment =
Cc[
"@mozilla.org/process/environment;1"]
43 .getService(
Ci.nsIEnvironment);
44 var resultFile = environment.get(
"SB_PERF_RESULTS");
46 log(
"DBPERF: " +
aName +
" ignored, since SB_PERF_RESULTS is not set.");
51 var timer =
new Timer();
52 aTestFunc.apply(
this, [library, timer]);
54 log(
"DBPERF: " +
aName +
" " + library.databaseGuid +
" " +
55 library.length +
" " + timer.elapsed() +
"ms");
57 var outputFile =
Cc[
"@mozilla.org/file/local;1"]
58 .createInstance(
Ci.nsILocalFile);
59 outputFile.initWithPath(resultFile);
61 var fos =
Cc[
"@mozilla.org/network/file-output-stream;1"]
62 .createInstance(
Ci.nsIFileOutputStream);
63 var s =
aName +
"\t" + library.databaseGuid +
"\t" +
64 library.length +
"\t" + timer.elapsed() +
"\n";
66 fos.init(outputFile, 0x02 | 0x08 | 0x10, 0666, 0);
67 fos.write(s, s.length);
72 var environment =
Cc[
"@mozilla.org/process/environment;1"]
73 .getService(
Ci.nsIEnvironment);
76 if (!environment.exists(
"SB_PERF_LIBRARY")) {
78 Components.utils.import(
"resource://app/jsmodules/sbLibraryUtils.jsm");
82 libraryFile = environment.get(
"SB_PERF_LIBRARY");
84 var
file = Components.classes[
"@mozilla.org/file/local;1"]
85 .createInstance(
Ci.nsILocalFile);
86 file.initWithPath(libraryFile);
89 Cc[
"@songbirdnest.com/Songbird/Library/LocalDatabase/LibraryFactory;1"]
90 .getService(
Ci.sbILibraryFactory);
91 var hashBag =
Cc[
"@mozilla.org/hash-property-bag;1"].
93 hashBag.setPropertyAsInterface(
"databaseFile", file);
94 return libraryFactory.createLibrary(hashBag);
104 this._startTime = Date.now();
107 this._stopTime = Date.now();
109 elapsed:
function() {
110 return this._stopTime - this._startTime;
114 function newGuidArray(aLibrary) {
115 var ldbl = aLibrary.QueryInterface(
Ci.sbILocalDatabaseLibrary);
116 var
array =
Cc[
"@songbirdnest.com/Songbird/Library/LocalDatabase/GUIDArray;1"]
117 .createInstance(
Ci.sbILocalDatabaseGUIDArray);
118 array.databaseGUID = ldbl.databaseGuid;
119 array.propertyCache = ldbl.propertyCache;
120 array.baseTable =
"media_items";
121 array.fetchSize = 1000;
127 var
file =
Cc[
"@mozilla.org/file/directory_service;1"]
128 .getService(
Ci.nsIProperties)
129 .get(
"resource:app",
Ci.nsIFile);
131 file.append(
"testharness");
132 file.append(
"localdatabaselibrary");
133 file.append(fileName);
138 this._array = aArray;
143 return this._current < this._array.length;
147 return this._array[this._current++];
151 if (!iid.equals(Components.interfaces.nsIStringEnumerator) &&
152 !iid.equals(Components.interfaces.nsISupports))
153 throw Components.results.NS_ERROR_NO_INTERFACE;
function stop(ch, cx, status, data)
function runPerfTest(aName, aTestFunc)
function getFile(fileName)
var localeCollationPreviouslyEnabled
function StringArrayEnumerator(aArray)
Javascript wrappers for common library tasks.
var SB_NS
Some globally useful stuff for the local database library tests.