Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
feat(test): add benchmark page
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaLiPassion committed Apr 25, 2018
1 parent 1ba8519 commit ec1407f
Show file tree
Hide file tree
Showing 8 changed files with 866 additions and 0 deletions.
84 changes: 84 additions & 0 deletions test/performance/eventTarget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
(function(_global) {
var testRunner = _global['__zone_symbol__testRunner'];
var mark = _global['__zone_symbol__mark'];
var measure = _global['__zone_symbol__measure'];
var zone = _global['__zone_symbol__callbackZone'];
var button;
var testTarget = {
title: 'addEventListener',
times: 10,
before: function() {
button = document.createElement('button');
document.body.appendChild(button);
_global['__zone_symbol__callbackContext'].measureName = 'addEventListener_callback';
_global['__zone_symbol__callbackContext'].type = 'eventTask';
_global['__zone_symbol__callbackContext'].source = 'addEventListener';
},
after: function() {
document.body.removeChild(button);
button = null;
},
apis: [
{
supportClear: true,
method: 'addEventListener',
nativeMethod: '__zone_symbol__addEventListener',
clearMethod: 'removeEventListener',
nativeClearMethod: '__zone_symbol__removeEventListener',
run: function() {
var listener = function() {};
button.addEventListener('click', listener);
return listener;
},
runClear: function(timerId) {
return button.removeEventListener('click', timerId);
},
nativeRun: function() {
var listener = function() {};
button['__zone_symbol__addEventListener']('click', listener);
return listener;
},
nativeRunClear: function(timerId) {
return button['__zone_symbol__removeEventListener']('click', timerId);
}
},
{
isCallback: true,
supportClear: false,
method: 'addEventListener_callback',
nativeMethod: 'native_addEventListener_callback',
run: function() {
var listener = function() {};
zone.run(function() {
button.addEventListener('click', listener);
});
var event = document.createEvent('Event');
event.initEvent('click', true, true);
button.dispatchEvent(event);
button.removeEventListener('click', listener);
},
nativeRun: function() {
var func = function() {};
var listener = function() {
mark('native_addEventListener_callback');
func.apply(this, arguments);
measure('native_addEventListener_callback', 'native_addEventListener_callback');
};
button['__zone_symbol__addEventListener']('click', listener);
var event = document.createEvent('Event');
event.initEvent('click', true, true);
button.dispatchEvent(event);
button['__zone_symbol__removeEventListener']('click', listener);
}
}
],
};
return testRunner(testTarget);
}(typeof window === 'undefined' ? global : window));
73 changes: 73 additions & 0 deletions test/performance/performance.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!DOCTYPE html>
<html>

<head>
<style>
table {
border-collapse: collapse;
}

table,
th,
td {
border: 1px solid black;
}

ul {
font-size: 24px
}

li {
font-size: 16px
}
</style>
<script src='../../dist/zone.js'></script>
<script src='./performance_setup.js'></script>
<script src='./performance_ui.js'></script>
<script src='./timeout.js'></script>
<script src='./requestAnimationFrame.js'></script>
<script src='./eventTarget.js'></script>
<script src='./xhr.js'></script>
<script src='./promise.js'></script>
<script>
window.onload = function () {
var jsonResult = {};

var div = document.getElementById('tests');
var json = document.getElementById('json');
var table = document.getElementById('summary');

var tests = window['__zone_symbol__performance_tasks'];
window['__zone_symbol__testTargetsUIBuild']({
tests: tests,
targetContainer: div,
resultsContainer: table,
jsonContainer: json,
jsonResult: jsonResult
});
}
</script>
</head>

<body>
<div id="thetext">Performance Bencnhmark of Zone.js vs Native Delegate!</div>
<div id="tests"></div>
<div>
<table id="summary" class="table">
<tr class="tableheader">
<th>
Module
</th>
<th>
API
</th>
<th>
Performance overhead
</th>
</tr>
</table>
</div>
<div id="json"></div>
</body>

</html>
Loading

0 comments on commit ec1407f

Please sign in to comment.