Debian Codegraph @

dojox/grid/tests/performance/_gridPerfFramework.js

raw symbols SCIP
1 dojo.require("dojo.data.ItemFileWriteStore");
2 dojo.provide("dojox.grid.tests.performance._gridPerfFramework");
3
4 (function(){
5 // some sample data
6 var data_list = [
7 { col1: "normal", col2: false, col3: "new", col4: 'But are not followed by two hexadecimal', col5: 29.91, col6: 10, col7: false },
8 { col1: "important", col2: false, col3: "new", col4: 'Because a % sign always indicates', col5: 9.33, col6: -5, col7: false },
9 { col1: "important", col2: true, col3: "read", col4: 'Signs can be selectively', col5: 19.34, col6: 0, col7: true },
10 { col1: "note", col2: false, col3: "read", col4: 'However the reserved characters', col5: 15.63, col6: 0, col7: true },
11 { col1: "normal", col2: true, col3: "replied", col4: 'It is therefore necessary', col5: 24.22, col6: 5.50, col7: true },
12 { col1: "important", col2: false, col3: "replied", col4: 'To problems of corruption by', col5: 9.12, col6: -3, col7: true },
13 { col1: "note", col2: false, col3: "replied", col4: 'Which would simply be awkward in', col5: 12.15, col6: -4, col7: false }
14 ];
15
16 // default querystring values
17 var default_obj = {rows: "100", layout: "single", rowSelector: "false", doProfiling: "false"};
18
19 // values for the performance tests
20 var iterations = 100;
21 var duration = 100;
22 var delay = 100;
23
24 // Store functions
25 var stores = {};
26 dojo.setObject("getStore", function(numRows, force){
27 if(force){
28 delete stores[numRows];
29 }
30 if(!stores[numRows]){
31 var data = {
32 identifier: 'id',
33 label: 'id',
34 items: []
35 };
36 for(var i=0, l=data_list.length; i<numRows; i++){
37 data.items.push(dojo.mixin({ id: i }, data_list[i%l]));
38 }
39 stores[numRows] = new dojo.data.ItemFileWriteStore({data: data});
40 }
41 return stores[numRows];
42 });
43
44 // Layout generation functions
45 dojo.setObject("getLayout", function(type){
46 switch (type.toLowerCase()){
47 case "dual":
48 return [{
49 cells: [
50 {name: 'Column 0', field: 'id', width: '100px' },
51 {name: 'Column 1', field: 'col1', width: '100px' },
52 {name: 'Column 2', field: 'col2', width: '100px' },
53 {name: 'Column 3', field: 'col3', width: '100px' }
54 ],
55 noscroll: true
56 },{
57 cells: [
58 {name: 'Column 4', field: 'col4', width: '300px' },
59 {name: 'Column 5', field: 'col5', width: '150px' },
60 {name: 'Column 6', field: 'col6', width: '150px' },
61 {name: 'Column 7', field: 'col7', width: '150px' },
62 {name: 'Column 8', field: 'col8', width: '150px' }
63 ]
64 }];
65 case "single":
66 default:
67 return [
68 [
69 { name: 'Column 0', field: 'id', width: '10%' },
70 { name: 'Column 1', field: 'col1', width: '10%' },
71 { name: 'Column 2', field: 'col2', width: '10%' },
72 { name: 'Column 3', field: 'col3', width: '10%' },
73 { name: 'Column 4', field: 'col4', width: '20%' },
74 { name: 'Column 5', field: 'col5', width: '10%' },
75 { name: 'Column 6', field: 'col6', width: '10%' },
76 { name: 'Column 7', field: 'col7', width: '10%' },
77 { name: 'Column 8', field: 'col3', width: '10%' }
78 ]
79 ];
80 }
81 });
82
83 // Returns the parameters in the query string as an object
84 // It mixes in over the defaultObj you pass it - if you pass
85 // true, it will mix in over the global default obj.
86 dojo.setObject("searchParamsAsObj", function(defaultObj){
87 var s = (window.location.search||"").replace(/^\?/, "");
88 var p = s.split("&");
89 var o = {}
90 dojo.forEach(p, function(i){
91 var b = i.split("=");
92 o[b[0]] = b[1];
93 });
94 if(defaultObj === true){
95 defaultObj = default_obj;
96 }
97 return dojo.mixin(dojo.clone(defaultObj||{}), o);
98 });
99
100 // Gets the tests for a row/layout/selector type test (the common one)
101 // This parses the object and returns a single instance and either perf
102 // tests (if run within the runner) or buttons for changing value (if
103 // run directly)
104 //
105 // getRunFunction is the core function to call. It gets the row, layout
106 // and selector values, as well as a boolean if it's a perf function or
107 // not.
108 dojo.setObject("getRLSTests", function(getRunFunction, getSetUpFunction, getTearDownFunction){
109 var isTop = (window.top == window);
110 var obj = searchParamsAsObj(default_obj);
111 var rows = parseInt(obj.rows, 10);
112 var layout = obj.layout;
113 var rowSelector = (obj.rowSelector.toLowerCase() == "true");
114 var doProfiling = isTop && dojo.isMoz && obj.doProfiling.toLowerCase() == "true";
115 var name = layout + " Layout" + (rowSelector ? " w/ Row Selector" : "");
116 var t = {
117 name: name,
118 runTest: getRunFunction(rows, layout, rowSelector, doProfiling, false)
119 };
120 if(getSetUpFunction){
121 t.setUp = getSetUpFunction(rows, layout, rowSelector, doProfiling, false);
122 }
123 if(getTearDownFunction){
124 t.tearDown = getTearDownFunction(rows, layout, rowSelector, doProfiling, false);
125 }
126 var tests = [ t ];
127 if(isTop && !window._buttonsAdded){
128 // Give buttons amd text boxes for changing views/rows/etc
129 var n = dojo.query(".heading")[0];
130 n = dojo.create("span", {innerHTML: "Rows: "}, n, "after");
131 n = dojo.create("input", {
132 type: "text",
133 value: rows,
134 size: 5,
135 onchange: function(){
136 v = parseInt(this.value, 10);
137 if(v && !isNaN(v)){
138 window.location.search="?rows=" + v +
139 "&layout=" + layout +
140 "&rowSelector=" + (rowSelector ? "true" : "false") +
141 "&doProfiling=" + (doProfiling ? "true" : "false");
142 }
143 }
144 }, n, "after");
145 n = dojo.create("button", {
146 innerHTML: layout == "single" ? "Dual Layout" : "Single Layout",
147 onclick: function(){window.location.search="?rows=" + rows +
148 "&layout=" + (layout == "single" ? "dual" : "single") +
149 "&rowSelector=" + (rowSelector ? "true" : "false") +
150 "&doProfiling=" + (doProfiling ? "true" : "false")}
151 }, n, "after");
152 n = dojo.create("button", {
153 innerHTML: rowSelector ? "Remove Row Selector" : "Add Row Selector",
154 onclick: function(){window.location.search="?rows=" + rows +
155 "&layout=" + layout +
156 "&rowSelector=" + (!rowSelector ? "true" : "false") +
157 "&doProfiling=" + (doProfiling ? "true" : "false")}
158 }, n, "after");
159 if(dojo.isMoz){
160 n = dojo.create("button", {
161 innerHTML: doProfiling ? "No Profiling" : "Do Profiling",
162 onclick: function(){window.location.search="?rows=" + rows +
163 "&layout=" + layout +
164 "&rowSelector=" + (rowSelector ? "true" : "false") +
165 "&doProfiling=" + (!doProfiling ? "true" : "false")}
166 }, n, "after");
167 }
168 window._buttonsAdded = true;
169 }else if (!isTop){
170 // Only run the perf tests if we are within the runner (which
171 // gives us pretty graphs and statistics...)
172 t = {
173 name: "Perf " + name,
174 testType: "perf",
175 trialDuration: duration,
176 trialIterations: iterations,
177 trialDelay: delay,
178 runTest: getRunFunction(rows, layout, rowSelector, doProfiling, true)
179 }
180 if(getSetUpFunction){
181 t.setUp = getSetUpFunction(rows, layout, rowSelector, doProfiling, true);
182 }
183 if(getTearDownFunction){
184 t.tearDown = getTearDownFunction(rows, layout, rowSelector, doProfiling, true);
185 }
186 tests.push(t);
187 }
188 return tests;
189 })
190
191 })();