@@ -10,6 +10,10 @@ const suites: Array<
1010 title : string ;
1111 eval : string ;
1212 times ?: number ; // defaults to 5
13+ recordOptions ?: {
14+ maskTextClass ?: string ;
15+ unmaskTextClass ?: string ;
16+ } ;
1317 } & ( { html : string } | { url : string } )
1418> = [
1519 // {
@@ -42,6 +46,25 @@ const suites: Array<
4246 eval : 'window.workload()' ,
4347 times : 5 ,
4448 } ,
49+ {
50+ title : 'mask 1000x10 DOM nodes' ,
51+ html : 'benchmark-text-masking.html' ,
52+ eval : 'window.workload()' ,
53+ times : 10 ,
54+ recordOptions : {
55+ maskTextClass : 'rr-mask' ,
56+ } ,
57+ } ,
58+ {
59+ title : 'unmask 1000x10 DOM nodes' ,
60+ html : 'benchmark-text-masking.html' ,
61+ eval : 'window.workload()' ,
62+ times : 10 ,
63+ recordOptions : {
64+ maskTextClass : 'rr-mask' ,
65+ unmaskTextClass : 'rr-unmask' ,
66+ } ,
67+ } ,
4568] ;
4669
4770function avg ( v : number [ ] ) : number {
@@ -106,35 +129,40 @@ describe('benchmark: mutation observer', () => {
106129 } ;
107130
108131 const getDuration = async ( ) : Promise < number > => {
109- return ( await page . evaluate ( ( triggerWorkloadScript ) => {
110- return new Promise ( ( resolve , reject ) => {
111- let start = 0 ;
112- let lastEvent : eventWithTime | null ;
113- const options : recordOptions < eventWithTime > = {
114- emit : ( event ) => {
115- // console.log(event.type, event.timestamp);
116- if ( event . type !== 5 || event . data . tag !== 'FTAG' ) {
117- lastEvent = event ;
118- return ;
119- }
120- if ( ! lastEvent ) {
121- reject ( 'no events recorded' ) ;
122- return ;
123- }
124- resolve ( lastEvent . timestamp - start ) ;
125- } ,
126- } ;
127- const record = ( window as any ) . rrweb . record ;
128- record ( options ) ;
129-
130- start = Date . now ( ) ;
131- eval ( triggerWorkloadScript ) ;
132-
133- requestAnimationFrame ( ( ) => {
134- record . addCustomEvent ( 'FTAG' , { } ) ;
132+ return ( await page . evaluate (
133+ ( triggerWorkloadScript , recordOptions ) => {
134+ return new Promise ( ( resolve , reject ) => {
135+ let start = 0 ;
136+ let lastEvent : eventWithTime | null ;
137+ const options : recordOptions < eventWithTime > = {
138+ ...recordOptions ,
139+ emit : ( event ) => {
140+ // console.log(event.type, event.timestamp);
141+ if ( event . type !== 5 || event . data . tag !== 'FTAG' ) {
142+ lastEvent = event ;
143+ return ;
144+ }
145+ if ( ! lastEvent ) {
146+ reject ( 'no events recorded' ) ;
147+ return ;
148+ }
149+ resolve ( lastEvent . timestamp - start ) ;
150+ } ,
151+ } ;
152+ const record = ( window as any ) . rrweb . record ;
153+ record ( options ) ;
154+
155+ start = Date . now ( ) ;
156+ eval ( triggerWorkloadScript ) ;
157+
158+ requestAnimationFrame ( ( ) => {
159+ record . addCustomEvent ( 'FTAG' , { } ) ;
160+ } ) ;
135161 } ) ;
136- } ) ;
137- } , suite . eval ) ) as number ;
162+ } ,
163+ suite . eval ,
164+ suite . recordOptions || { }
165+ ) ) as number ;
138166 } ;
139167
140168 // generate profile.json file
0 commit comments