You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+32-13Lines changed: 32 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,28 +61,47 @@ These snippets are just meant to demonstrate the most basic of usage. Thanks to
61
61
The contract placed on the end user is very light. Keep Document alive for as long as you're storing or accessing any Node object, directly or indirectly. That's basically it.
62
62
63
63
##Speed
64
-
One of the primary goals with this engine was to maximize speed. For my purposes, I wanted to ensure I could run an insane amount of selectors without any visible delay to the user. Running the TestParser test benchmarks parsing and using every single selector in [EasyList](https://easylist.adblockplus.org/en/) (spare a handful which were removed because they're improperly formatted) against a standard high profile website's landing page HTML. The current results on my [dev laptop](https://www.asus.com/ca-en/ROG-Republic-Of-Gamers/ASUS_ROG_G750JM/) are:
64
+
One of the primary goals with this engine was to maximize speed. For my purposes, I wanted to ensure I could run an insane amount of selectors without any visible delay to the user. Running the TestParser test benchmarks parsing and using every single selector in [EasyList](https://easylist.adblockplus.org/en/) (spare a handful which were removed because they're improperly formatted) against a standard high profile website's landing page HTML. For example, if I download the source for the landing page of [yahoo.com](https://yahoo.com) and use it in the parser test at the time of this writing, the current results on my [dev laptop](https://www.asus.com/ca-en/ROG-Republic-Of-Gamers/ASUS_ROG_G750JM/) are:
65
65
66
66
```
67
67
Processed 27646 selectors. Had handled errors? false
68
68
Benchmarking parsing speed.
69
-
Time taken to parse 2764600 selectors: 2492.68 ms.
70
-
Processed at a rate of 0.00090164 milliseconds per selector or 1109.09 selectors per millisecond.
69
+
Time taken to parse 2764600 selectors: 2443.11 ms.
70
+
Processed at a rate of 0.000883713 milliseconds per selector or 1131.59 selectors per millisecond.
71
71
Benchmarking document parsing.
72
-
Time taken to parse 100 documents: 13102.2 ms.
73
-
Processed at a rate of 131.022 milliseconds per document.
72
+
Time taken to parse 100 documents: 8054.37 ms.
73
+
Processed at a rate of 80.5437 milliseconds per document.
74
74
Benchmarking selection speed.
75
-
Time taken to run 2764600 selectors against the document: 8783.99 ms producing 42900 total matches.
76
-
Processed at a rate of 0.00317731 milliseconds per selector or 314.732 selectors per millisecond.
75
+
Time taken to run 2764600 selectors against the document: 5709.75 ms producing 23300 total matches.
76
+
Processed at a rate of 0.00206531 milliseconds per selector or 484.189 selectors per millisecond.
77
77
Benchmarking mutation.
78
-
Time taken to run 27646 selectors against the document while serializing with mutations 100 times: 9169.81 ms.
79
-
Time per cycle 91.6981 ms.
80
-
Processed at a rate of 0.00331687 milliseconds per selector or 301.489 selectors per millisecond.
78
+
Time taken to run 27646 selectors against the document while serializing with mutations 100 times: 6110.32 ms.
79
+
Time per cycle 61.1032 ms.
80
+
Processed at a rate of 0.0022102 milliseconds per selector or 452.448 selectors per millisecond.
81
81
```
82
82
83
-
So from these results, a document could be loaded, parsed, and have 27646 precompiled selectors run on it in about **218.8619** milliseconds, a little shy of a quarter of a second. Based on the latest benchmarks (that actually included mutation during serialization) it's about ***222.7201*** msec to load, parse the document, run 27646 selectors and serialize the output with modifications based on those selectors back to a html string.
84
-
85
-
That's almost stretching the "user doesn't notice" goal, but thankfully nowhere near 30K selectors would ever actually need to be run at once. In a more realistic use case of the EasyList, less than half that number of selectors would run on any given html input.
83
+
So from these results, a document could be loaded, parsed, and have 27646 precompiled selectors run on it in about **137.6412** milliseconds. If you include reserializing the input to an HTML string with modifications, it's about ***141.6469*** msec to load, parse the document, run 27646 selectors and serialize the output with modifications based on those selectors back to a html string.
84
+
85
+
It should be obvious that the speed can greatly vary depending on the size and complexity of the input HTML. For example, running the same test program against the [cnn.com](http://cnn.com) landing page yields the following results:
86
+
87
+
```
88
+
Processed 27646 selectors. Had handled errors? false
89
+
Benchmarking parsing speed.
90
+
Time taken to parse 2764600 selectors: 2396.14 ms.
91
+
Processed at a rate of 0.000866723 milliseconds per selector or 1153.77 selectors per millisecond.
92
+
Benchmarking document parsing.
93
+
Time taken to parse 100 documents: 2081.5 ms.
94
+
Processed at a rate of 20.815 milliseconds per document.
95
+
Benchmarking selection speed.
96
+
Time taken to run 2764600 selectors against the document: 3321.3 ms producing 9900 total matches.
97
+
Processed at a rate of 0.00120137 milliseconds per selector or 832.386 selectors per millisecond.
98
+
Benchmarking mutation.
99
+
Time taken to run 27646 selectors against the document while serializing with mutations 100 times: 3478.62 ms.
100
+
Time per cycle 34.7862 ms.
101
+
Processed at a rate of 0.00125827 milliseconds per selector or 794.741 selectors per millisecond.
102
+
```
103
+
104
+
As you can see, approaching double the speed over the [yahoo.com](https://yahoo.com) website's landing page.
86
105
87
106
Speed doesn't mean much if the matching code is broken. As such, over 40 tests currently exist that ensure correct functionality of various types of selectors. ~~I have yet to write tests for nested and combined selectors.~~
0 commit comments