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