1
- import benchmark from 'htmlparser-benchmark' ;
2
1
import high5 from "high5" ;
2
+ import benchmark from 'htmlparser-benchmark' ;
3
3
4
4
const Parser = high5 ;
5
5
@@ -9,50 +9,54 @@ var token = [],
9
9
10
10
function noop ( ) { }
11
11
12
-
13
-
14
- var bench = benchmark ( function ( html , callback ) {
15
- var parser = new Parser ( {
16
- token : token ,
17
- onopentagname : function ( n ) {
18
- attribs = { } ;
19
- tag = [ "StartTag" , n , attribs ] ;
20
- } ,
21
- onclosetag : function ( n ) {
22
- token . push ( [ "EndTag" , n ] ) ;
23
- } ,
24
- ontext : function ( t ) {
25
- token . push ( [ "Character" , t ] ) ;
26
- } ,
27
- oncomment : function ( t ) {
28
- token . push ( [ "Comment" , t ] ) ;
29
- } ,
30
- onattribute : function ( n , v ) {
31
- if ( ! ( n in attribs ) ) attribs [ n ] = v ;
32
- } ,
33
- onopentagend : function ( ) {
34
- token . push ( tag ) ;
35
- tag = attribs = null ;
36
- } ,
37
- onselfclosingtag : function ( ) {
38
- tag . push ( true ) ;
39
- token . push ( tag ) ;
40
- tag = attribs = null ;
41
- } ,
42
- ondoctype : function ( name , publicIdent , systemIdent , normalMode ) {
43
- token . push ( [ "DOCTYPE" , name , publicIdent , systemIdent , normalMode ] ) ;
44
- } ,
45
- oncommentend : noop ,
46
- onend : callback ,
47
- onerror : callback
12
+ export default function high5parse ( ) {
13
+ return new Promise ( ( res ) => {
14
+
15
+ var bench = benchmark ( function ( html , callback ) {
16
+ var parser = new Parser ( {
17
+ token : token ,
18
+ onopentagname : function ( n ) {
19
+ attribs = { } ;
20
+ tag = [ "StartTag" , n , attribs ] ;
21
+ } ,
22
+ onclosetag : function ( n ) {
23
+ token . push ( [ "EndTag" , n ] ) ;
24
+ } ,
25
+ ontext : function ( t ) {
26
+ token . push ( [ "Character" , t ] ) ;
27
+ } ,
28
+ oncomment : function ( t ) {
29
+ token . push ( [ "Comment" , t ] ) ;
30
+ } ,
31
+ onattribute : function ( n , v ) {
32
+ if ( ! ( n in attribs ) ) attribs [ n ] = v ;
33
+ } ,
34
+ onopentagend : function ( ) {
35
+ token . push ( tag ) ;
36
+ tag = attribs = null ;
37
+ } ,
38
+ onselfclosingtag : function ( ) {
39
+ tag . push ( true ) ;
40
+ token . push ( tag ) ;
41
+ tag = attribs = null ;
42
+ } ,
43
+ ondoctype : function ( name , publicIdent , systemIdent , normalMode ) {
44
+ token . push ( [ "DOCTYPE" , name , publicIdent , systemIdent , normalMode ] ) ;
45
+ } ,
46
+ oncommentend : noop ,
47
+ onend : callback ,
48
+ onerror : callback
49
+ } ) ;
50
+ parser . end ( html ) ;
51
+ } ) ;
52
+
53
+ bench . on ( 'progress' , function ( key ) {
54
+ // console.log('finished parsing ' + key + '.html');
55
+ } ) ;
56
+
57
+ bench . on ( 'result' , function ( stat ) {
58
+ console . log ( 'high5 :' + stat . mean ( ) . toPrecision ( 6 ) + ' ms/file ± ' + stat . sd ( ) . toPrecision ( 6 ) ) ;
59
+ res ( ) ;
60
+ } ) ;
48
61
} ) ;
49
- parser . end ( html ) ;
50
- } ) ;
51
-
52
- bench . on ( 'progress' , function ( key ) {
53
- // console.log('finished parsing ' + key + '.html');
54
- } ) ;
55
-
56
- bench . on ( 'result' , function ( stat ) {
57
- console . log ( 'high5 :' + stat . mean ( ) . toPrecision ( 6 ) + ' ms/file ± ' + stat . sd ( ) . toPrecision ( 6 ) ) ;
58
- } ) ;
62
+ }
0 commit comments