Permalink
Browse files

adding a speed test case for setdocument context switching, thx to in…

…viz for the help and for implementing the slowdoc mock.
  • Loading branch information...
1 parent 7af5c4b commit 453edbb6cf15b9b81364fe446c9aa52c888929a6 @fabiomcosta fabiomcosta committed Feb 20, 2011
@@ -8,7 +8,7 @@
<body>
<h2>Speed tests</h2>
<ul>
- <li><a href="setdocument.html">setdocument.html</a></li>
+ <li><a href="setdocument">setdocument.html</a></li>
</ul>
</body>
</html>
@@ -1,33 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
- "http://www.w3.org/TR/html4/strict.dtd">
-<html>
- <head>
- <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
- <title>setdocument</title>
- <script type="text/javascript" src="../benchmarkjs/benchmark.js"></script>
- </head>
- <body>
- <applet code="nano" archive="../benchmarkjs/nano.jar"></applet>
- <script type="text/javascript">
- var suite = new Benchmark.Suite;
- // add tests
- suite.add('RegExp#test', function() {
- /o/.test('Hello World!');
- })
- .add('String#indexOf', function() {
- 'Hello World!'.indexOf('o') > -1;
- })
- .add('String#match', function() {
- !!'Hello World!'.match(/o/);
- })
- // add listeners
- .on('cycle', function(bench) {
- console.log(String(bench));
- })
- .on('complete', function() {
- console.log('Fastest is ' + this.filter('fastest').pluck('name'));
- })
- .run(true);
- </script>
- </body>
-</html>
@@ -0,0 +1,41 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+ "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+ <head>
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
+ <title>setdocument</title>
+ <script type="text/javascript" src="../../benchmarkjs/benchmark.js"></script>
+ <script src="https://github.com/mootools/slick/raw/d3aef7cb747c127f2dd33a608769678ed4e7f9ef/Source/Slick.Finder.js" type="text/javascript" charset="utf-8"></script>
+ <script type="text/javascript">
+ oldSlick = window.Slick;
+ delete window.Slick;
+ </script>
+ <script src="../../../Source/Slick.Parser.js" type="text/javascript"></script>
+ <script src="../../../Source/Slick.Finder.js" type="text/javascript"></script>
+ <script src="slow-document.js" type="text/javascript"></script>
+ </head>
+ <body>
+ <applet code="nano" archive="../../benchmarkjs/nano.jar"></applet>
+ <script type="text/javascript">
+ var suite = new Benchmark.Suite;
+ // add tests
+ suite
+ .add('Old Slick', function() {
+ oldSlick.search(document, 'div');
+ oldSlick.search(doc, 'div');
+ })
+ .add('Current Slick', function() {
+ Slick.search(document, 'div');
+ Slick.search(doc, 'div');
+ })
+ // add listeners
+ .on('cycle', function(bench) {
+ console.log(String(bench));
+ })
+ .on('complete', function() {
+ console.log('Fastest is ' + this.filter('fastest').pluck('name'));
+ })
+ .run(true);
+ </script>
+ </body>
+</html>
@@ -0,0 +1,69 @@
+var Slow = {};
+Slow.Document = function(element) {
+ this.body = element;
+ this.document = this.documentElement = this;
+
+ this.xml = true;
+ this.navigator = {};
+ this.attributes = {};
+
+ this.nodeType = 9;
+}
+
+Slow.Document.prototype = {
+ /*
+ Slick.Finder tries to probe document it was given to determine
+ capabilities of the engine and possible quirks that will alter
+ the desired results.
+
+ We try to emulate XML-tree (simple built-in querying capabilities),
+ so all of the traversing work happens inside of Slick except
+ getElementsByTagName which is provided by LSD.Module.DOM.
+
+ So the problem is that Slick creates element and tries to
+ append it to the document which is unacceptable (because every node
+ in LSD.Document means widget instance, and we dont want that for
+ dummy elements). The solution is to ignore those elements.
+ */
+ createElement: function(tag) {
+ return {
+ innerText: '',
+ mock: true
+ }
+ },
+
+ appendChild: function(widget) {
+ if (widget.mock) return false;
+ },
+
+ removeChild: function(widget) {
+ if (widget.mock) return false;
+ },
+
+ getAttribute: function(name) {
+ return this.attributes[name]
+ },
+
+ setAttribute: function(name, value) {
+ return this.attributes[name] = value;
+ },
+
+ getElementsByTagName: function() {
+ return parent.childNodes;
+ }
+}
+
+Slow.Node = function() {
+ this.nodeType = 1;
+ this.parentNode = this.nextSibling = this.previousSibling = null;
+ this.nodeName = this.tagName = 'div';
+ this.childNodes = [];
+ this.appendChild = this.removeChild = function(){};
+}
+
+var doc = new Slow.Document(document.body);
+var parent = new Slow.Node();
+for (var i = 0; i < 10; i++) {
+ var child = new Slow.Node;
+ parent.childNodes.push(child);
+}

0 comments on commit 453edbb

Please sign in to comment.