-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Site editor: add typing performance test (#32553)
- Loading branch information
Showing
4 changed files
with
174 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { existsSync, readFileSync, unlinkSync } from 'fs'; | ||
|
||
export function readFile( filePath ) { | ||
return existsSync( filePath ) | ||
? readFileSync( filePath, 'utf8' ).trim() | ||
: ''; | ||
} | ||
|
||
export function deleteFile( filePath ) { | ||
if ( existsSync( filePath ) ) { | ||
unlinkSync( filePath ); | ||
} | ||
} | ||
|
||
function isEvent( item ) { | ||
return ( | ||
item.cat === 'devtools.timeline' && | ||
item.name === 'EventDispatch' && | ||
item.dur && | ||
item.args && | ||
item.args.data | ||
); | ||
} | ||
|
||
function isKeyDownEvent( item ) { | ||
return isEvent( item ) && item.args.data.type === 'keydown'; | ||
} | ||
|
||
function isKeyPressEvent( item ) { | ||
return isEvent( item ) && item.args.data.type === 'keypress'; | ||
} | ||
|
||
function isKeyUpEvent( item ) { | ||
return isEvent( item ) && item.args.data.type === 'keyup'; | ||
} | ||
|
||
function isFocusEvent( item ) { | ||
return isEvent( item ) && item.args.data.type === 'focus'; | ||
} | ||
|
||
function isClickEvent( item ) { | ||
return isEvent( item ) && item.args.data.type === 'click'; | ||
} | ||
|
||
function isMouseOverEvent( item ) { | ||
return isEvent( item ) && item.args.data.type === 'mouseover'; | ||
} | ||
|
||
function isMouseOutEvent( item ) { | ||
return isEvent( item ) && item.args.data.type === 'mouseout'; | ||
} | ||
|
||
function getEventDurationsForType( trace, filterFunction ) { | ||
return trace.traceEvents | ||
.filter( filterFunction ) | ||
.map( ( item ) => item.dur / 1000 ); | ||
} | ||
|
||
export function getTypingEventDurations( trace ) { | ||
return [ | ||
getEventDurationsForType( trace, isKeyDownEvent ), | ||
getEventDurationsForType( trace, isKeyPressEvent ), | ||
getEventDurationsForType( trace, isKeyUpEvent ), | ||
]; | ||
} | ||
|
||
export function getSelectionEventDurations( trace ) { | ||
return [ getEventDurationsForType( trace, isFocusEvent ) ]; | ||
} | ||
|
||
export function getClickEventDurations( trace ) { | ||
return [ getEventDurationsForType( trace, isClickEvent ) ]; | ||
} | ||
|
||
export function getHoverEventDurations( trace ) { | ||
return [ | ||
getEventDurationsForType( trace, isMouseOverEvent ), | ||
getEventDurationsForType( trace, isMouseOutEvent ), | ||
]; | ||
} |