Skip to content

Commit

Permalink
- Updated slickspeed, using operations/ms, running tests at least 1s…
Browse files Browse the repository at this point in the history
…ec. - Minor Sly fixes.
  • Loading branch information
Harald Kirschner committed Mar 30, 2009
1 parent 44cfb51 commit 44e08b3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 29 deletions.
14 changes: 8 additions & 6 deletions Sly.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,18 @@ var support = Sly.support = {};
support.hasQsa = !!(testee.querySelectorAll && testee.querySelectorAll('.Â').length);

support.hasByClass = (function() {
if (!testee.getElementsByClassName || !testee.getElementsByClassName('.b').length) return false;
if (!testee.getElementsByClassName || !testee.getElementsByClassName('b').length) return false;
testee.firstChild.className = 'c';
return (testee.getElementsByClassName('.c').length == 1);
return (testee.getElementsByClassName('c').length == 1);
})();

/* not needed, checks id by default (no speed issue)
var root = document.documentElement;
testee.insertBefore(root, root.firstChild);
root.insertBefore(testee, root.firstChild);

// IE returns named nodes for getElementById(name)
support.byIdAddsName = !!(document.getElementById(id));

root.removeChild(testee);
*/

})();

Expand Down Expand Up @@ -441,7 +439,11 @@ proto.compute = function(selector) {
search = function(context) {
if (context.getElementById) {
var el = context.getElementById(id);
return (el && el.id == id && (!nodeName || el.nodeName.toUpperCase() == nodeName)) ? [el] : [];
return (el
&& (!nodeName || el.nodeName.toUpperCase() == nodeName)
&& (!support.getIdAdds || el.id == id))
? [el]
: [];
}

var query = context.getElementsByTagName(tag || '*');
Expand Down
16 changes: 10 additions & 6 deletions speed/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@
; file = "domass.js"
; function = "$"

[Dojo Acme]
file = "dojo-acme.js"
function = "acme.query"
[Dojo]
file = "dojo.js"
function = "dojo.query"

[querySelectorAll]
file = "native.js"
function = "document.querySelectorAll"
; [Dojo Acme]
; file = "dojo-acme.js"
; function = "acme.query"

; [querySelectorAll]
; file = "native.js"
; function = "document.querySelectorAll"

; just add a framework here following the conventions to add another framework.
; the function parameter is to choose the right css selector function name
Expand Down
11 changes: 6 additions & 5 deletions speed/system/slickspeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ window.onload = function load(){
if (!test) return;
var results = test.execute(test.selector);
function handleResults(){
var ops = results && results.ops || 0;
test.cell.className = 'test';
test.cell.innerHTML = '<b>'+Math.round(results.time*10)/10 + ' ms</b><b>' + results.found + ' found</b>';
test.cell.speed = results.time;
test.cell.innerHTML = '<b>'+Math.round(ops * 10)/10 + ' ops/ms</b><b>' + results.found + ' found</b>';
test.cell.speed = results.ops || 0;
if (results.error){
test.cell.innerHTML = results.time + ' ms | <span class="exception" title="' + results.error + '">error returned</a>';
test.cell.innerHTML = ops + ' ops/s | <span class="exception" title="' + results.error + '">error returned</a>';
test.cell.className += ' exception';
test.cell.found = 0;
test.cell.error = true;
Expand Down Expand Up @@ -134,9 +135,9 @@ window.onload = function load(){
}
});
}
if (cell.found && cell.speed == min) cell.className += ' good';
if (cell.found && cell.speed == max) cell.className += ' good';
else if (!cell.found) cell.className += ' zero';
else if (cell.speed == max) cell.className += ' bad';
else if (cell.speed == min) cell.className += ' bad';
else cell.className += ' normal';
});

Expand Down
25 changes: 13 additions & 12 deletions speed/system/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,25 @@ function test(selector){
<?php if (strpos($_GET['function'], '%') === false):
$_GET['function'] = $_GET['function'] . '(%1$s, %2$s)';
endif; ?>

var once = function() {
return <?php echo sprintf($_GET['function'], 'selector', 'context') ?>;
}

var start = (new Date()).getTime(), distance = 0, comps = 0, elements;

<?php for ($i = 0; $i < 10; $i++): ?>
times[i]={ start:new Date() };
var elements = <?php echo sprintf($_GET['function'], 'selector', 'context') ?>;
times[i++].end = new Date();
<?php endfor; ?>
var elements = once();

do {
comps++;
once();
} while ((distance = (new Date()).getTime() - start) < 1000);

var end = new Date();
var data = { time:0, found:get_length(elements) };

for (var N=0; N < times.length; N++) {
if (!times[N]) continue;
data.time += (times[N].end - times[N].start);
}
data.time && (data.time /= times.length);
data.time || (data.time=0);
data.ops = comps / 100;

data.time = (end - start) / i;
return data;
} catch(err){
if (elements == undefined) elements = {length: -1};
Expand Down

0 comments on commit 44e08b3

Please sign in to comment.