1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/xslt/tests/XSLTMark/XSLTMark-view.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,175 @@ 1.4 +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +var view = 1.10 +{ 1.11 + configUrl: null, 1.12 + testArray: null, 1.13 + mCurrent: null, 1.14 + 1.15 + browseForConfig: function() 1.16 + { 1.17 + enablePrivilege('UniversalXPConnect'); 1.18 + var fp = Components.classes["@mozilla.org/filepicker;1"]. 1.19 + createInstance(nsIFilePicker); 1.20 + fp.init(window,'XSLTMark Description File',nsIFilePicker.modeOpen); 1.21 + fp.appendFilter('*.conf', '*.conf'); 1.22 + fp.appendFilters(nsIFilePicker.filterAll); 1.23 + var res = fp.show(); 1.24 + 1.25 + if (res == nsIFilePicker.returnOK) { 1.26 + this.configUrl = Components.classes[STDURL_CTRID].createInstance(nsIURI); 1.27 + this.configUrl.spec = fp.fileURL.spec; 1.28 + document.getElementById('config').setAttribute('value', this.configUrl.spec); 1.29 + } 1.30 + this.parseConfig(); 1.31 + return true; 1.32 + }, 1.33 + 1.34 + parseConfig: function() 1.35 + { 1.36 + this.testArray = new Array(); 1.37 + var test; 1.38 + if (!this.configUrl) { 1.39 + return; 1.40 + } 1.41 + 1.42 + var content = loadFile(this.configUrl.spec); 1.43 + 1.44 + var lines = content.split("\n"); 1.45 + var line, res; 1.46 + var head = /^\[(.+)\]$/; 1.47 + var instruct = /^(.+)=(.+)$/; 1.48 + while (lines.length) { 1.49 + line = lines.shift(); 1.50 + if (head.test(line)) { 1.51 + test = new Object; 1.52 + res = head.exec(line); 1.53 + test['title'] = res[1]; 1.54 + this.testArray.push(test); 1.55 + } 1.56 + else if (line == '') { 1.57 + test = undefined; 1.58 + } 1.59 + else { 1.60 + res = instruct.exec(line); 1.61 + test[res[1]] = res[2]; 1.62 + } 1.63 + } 1.64 + }, 1.65 + 1.66 + onLoad: function() 1.67 + { 1.68 + this.mCurrentStatus = document.getElementById('currentStatus'); 1.69 + this.mCurrentProgress = document.getElementById('currentProgress'); 1.70 + this.mTotalProgress = document.getElementById('totalProgress'); 1.71 + this.mOutput = document.getElementById('transformOutput'); 1.72 + this.mDetailOutput = 1.73 + document.getElementById('transformDetailedOutput'); 1.74 + this.mDetail = true; 1.75 + }, 1.76 + 1.77 + progress: function(aTitle, aTime, aProgress) 1.78 + { 1.79 + // dump20(aTitle); 1.80 + // dump20(aTime); 1.81 + // dump20(aProgress); 1.82 + this.mCurrentProgress.value = aProgress; 1.83 + this.displayDetailTime(aTime); 1.84 + this.mTimes.push(aTime); 1.85 + // dump("\n"); 1.86 + }, 1.87 + 1.88 + done: function(aTitle) 1.89 + { 1.90 + // dump(aTitle + " is finished.\n"); 1.91 + this.mCurrent++; 1.92 + this.mCurrentProgress.value = 0; 1.93 + this.displayTotalTime(); 1.94 + if (this.mCurrent >= this.testArray.length) { 1.95 + this.mTotalProgress.value = 0; 1.96 + this.mCurrentStatus.value = "done"; 1.97 + return; 1.98 + } 1.99 + this.mTotalProgress.value = this.mCurrent*100/this.testArray.length; 1.100 + var test = this.testArray[this.mCurrent]; 1.101 + enablePrivilege('UniversalXPConnect'); 1.102 + this.displayTest(test.title); 1.103 + runTest(test.title, this.configUrl.resolve(test.input), 1.104 + this.configUrl.resolve(test.stylesheet), 1.105 + test.iterations, this); 1.106 + }, 1.107 + 1.108 + onStop: function() 1.109 + { 1.110 + clearTimeout(gTimeout); 1.111 + this.mCurrentProgress.value = 0; 1.112 + this.mTotalProgress.value = 0; 1.113 + this.mCurrentStatus.value = "stopped"; 1.114 + }, 1.115 + 1.116 + displayTest: function(aTitle) 1.117 + { 1.118 + this.mTimes = new Array; 1.119 + aTitle += "\t"; 1.120 + this.mCurrentStatus.value = aTitle; 1.121 + this.mOutput.value += aTitle; 1.122 + if (this.mDetail) { 1.123 + this.mDetailOutput.value += aTitle; 1.124 + } 1.125 + }, 1.126 + 1.127 + displayDetailTime: function(aTime) 1.128 + { 1.129 + if (this.mDetail) { 1.130 + this.mDetailOutput.value += aTime + " ms\t"; 1.131 + } 1.132 + }, 1.133 + 1.134 + displayTotalTime: function() 1.135 + { 1.136 + var sum = 0; 1.137 + for (k = 0; k < this.mTimes.length; k++) { 1.138 + sum += this.mTimes[k]; 1.139 + } 1.140 + var mean = sum / this.mTimes.length; 1.141 + this.mOutput.value += Number(mean).toFixed(2) + " ms\t" + sum + " ms\t"; 1.142 + var variance = 0; 1.143 + for (k = 0; k < this.mTimes.length; k++) { 1.144 + var n = this.mTimes[k] - mean; 1.145 + variance += n*n; 1.146 + } 1.147 + variance = Math.sqrt(variance/this.mTimes.length); 1.148 + this.mOutput.value += Number(variance).toFixed(2)+"\n"; 1.149 + if (this.mDetail) { 1.150 + this.mDetailOutput.value += "\n"; 1.151 + } 1.152 + }, 1.153 + 1.154 + runBenchmark: function() 1.155 + { 1.156 + enablePrivilege('UniversalXPConnect'); 1.157 + if (!this.testArray) { 1.158 + if (!this.configUrl) { 1.159 + this.configUrl = Components.classes[STDURL_CTRID].createInstance(nsIURI); 1.160 + this.configUrl.spec = document.getElementById('config').value; 1.161 + } 1.162 + this.parseConfig(); 1.163 + } 1.164 + 1.165 + this.mCurrent = 0; 1.166 + var test = this.testArray[this.mCurrent]; 1.167 + this.mOutput.value = ''; 1.168 + if (this.mDetail) { 1.169 + this.mDetailOutput.value = ''; 1.170 + } 1.171 + this.displayTest(test.title); 1.172 + runTest(test.title, this.configUrl.resolve(test.input), 1.173 + this.configUrl.resolve(test.stylesheet), 1.174 + test.iterations, this); 1.175 + return true; 1.176 + } 1.177 +} 1.178 +