dom/xslt/tests/XSLTMark/XSLTMark-view.js

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

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

mercurial