XSLTMark-view.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. var view =
  6. {
  7. configUrl: null,
  8. testArray: null,
  9. mCurrent: null,
  10. browseForConfig: function()
  11. {
  12. enablePrivilege('UniversalXPConnect');
  13. var fp = Components.classes["@mozilla.org/filepicker;1"].
  14. createInstance(nsIFilePicker);
  15. fp.init(window,'XSLTMark Description File',nsIFilePicker.modeOpen);
  16. fp.appendFilter('*.conf', '*.conf');
  17. fp.appendFilters(nsIFilePicker.filterAll);
  18. var res = fp.show();
  19. if (res == nsIFilePicker.returnOK) {
  20. this.configUrl = Components.classes[STDURL_CTRID].createInstance(nsIURI);
  21. this.configUrl.spec = fp.fileURL.spec;
  22. document.getElementById('config').setAttribute('value', this.configUrl.spec);
  23. }
  24. this.parseConfig();
  25. return true;
  26. },
  27. parseConfig: function()
  28. {
  29. this.testArray = new Array();
  30. var test;
  31. if (!this.configUrl) {
  32. return;
  33. }
  34. var content = loadFile(this.configUrl.spec);
  35. var lines = content.split("\n");
  36. var line, res;
  37. var head = /^\[(.+)\]$/;
  38. var instruct = /^(.+)=(.+)$/;
  39. while (lines.length) {
  40. line = lines.shift();
  41. if (head.test(line)) {
  42. test = new Object;
  43. res = head.exec(line);
  44. test['title'] = res[1];
  45. this.testArray.push(test);
  46. }
  47. else if (line == '') {
  48. test = undefined;
  49. }
  50. else {
  51. res = instruct.exec(line);
  52. test[res[1]] = res[2];
  53. }
  54. }
  55. },
  56. onLoad: function()
  57. {
  58. this.mCurrentStatus = document.getElementById('currentStatus');
  59. this.mCurrentProgress = document.getElementById('currentProgress');
  60. this.mTotalProgress = document.getElementById('totalProgress');
  61. this.mOutput = document.getElementById('transformOutput');
  62. this.mDetailOutput =
  63. document.getElementById('transformDetailedOutput');
  64. this.mDetail = true;
  65. },
  66. progress: function(aTitle, aTime, aProgress)
  67. {
  68. // dump20(aTitle);
  69. // dump20(aTime);
  70. // dump20(aProgress);
  71. this.mCurrentProgress.value = aProgress;
  72. this.displayDetailTime(aTime);
  73. this.mTimes.push(aTime);
  74. // dump("\n");
  75. },
  76. done: function(aTitle)
  77. {
  78. // dump(aTitle + " is finished.\n");
  79. this.mCurrent++;
  80. this.mCurrentProgress.value = 0;
  81. this.displayTotalTime();
  82. if (this.mCurrent >= this.testArray.length) {
  83. this.mTotalProgress.value = 0;
  84. this.mCurrentStatus.value = "done";
  85. return;
  86. }
  87. this.mTotalProgress.value = this.mCurrent*100/this.testArray.length;
  88. var test = this.testArray[this.mCurrent];
  89. enablePrivilege('UniversalXPConnect');
  90. this.displayTest(test.title);
  91. runTest(test.title, this.configUrl.resolve(test.input),
  92. this.configUrl.resolve(test.stylesheet),
  93. test.iterations, this);
  94. },
  95. onStop: function()
  96. {
  97. clearTimeout(gTimeout);
  98. this.mCurrentProgress.value = 0;
  99. this.mTotalProgress.value = 0;
  100. this.mCurrentStatus.value = "stopped";
  101. },
  102. displayTest: function(aTitle)
  103. {
  104. this.mTimes = new Array;
  105. aTitle += "\t";
  106. this.mCurrentStatus.value = aTitle;
  107. this.mOutput.value += aTitle;
  108. if (this.mDetail) {
  109. this.mDetailOutput.value += aTitle;
  110. }
  111. },
  112. displayDetailTime: function(aTime)
  113. {
  114. if (this.mDetail) {
  115. this.mDetailOutput.value += aTime + " ms\t";
  116. }
  117. },
  118. displayTotalTime: function()
  119. {
  120. var sum = 0;
  121. for (k = 0; k < this.mTimes.length; k++) {
  122. sum += this.mTimes[k];
  123. }
  124. var mean = sum / this.mTimes.length;
  125. this.mOutput.value += Number(mean).toFixed(2) + " ms\t" + sum + " ms\t";
  126. var variance = 0;
  127. for (k = 0; k < this.mTimes.length; k++) {
  128. var n = this.mTimes[k] - mean;
  129. variance += n*n;
  130. }
  131. variance = Math.sqrt(variance/this.mTimes.length);
  132. this.mOutput.value += Number(variance).toFixed(2)+"\n";
  133. if (this.mDetail) {
  134. this.mDetailOutput.value += "\n";
  135. }
  136. },
  137. runBenchmark: function()
  138. {
  139. enablePrivilege('UniversalXPConnect');
  140. if (!this.testArray) {
  141. if (!this.configUrl) {
  142. this.configUrl = Components.classes[STDURL_CTRID].createInstance(nsIURI);
  143. this.configUrl.spec = document.getElementById('config').value;
  144. }
  145. this.parseConfig();
  146. }
  147. this.mCurrent = 0;
  148. var test = this.testArray[this.mCurrent];
  149. this.mOutput.value = '';
  150. if (this.mDetail) {
  151. this.mDetailOutput.value = '';
  152. }
  153. this.displayTest(test.title);
  154. runTest(test.title, this.configUrl.resolve(test.input),
  155. this.configUrl.resolve(test.stylesheet),
  156. test.iterations, this);
  157. return true;
  158. }
  159. }