Skip to content

Commit

Permalink
benchmark for attribute mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
mdellanoce committed Nov 3, 2023
1 parent fed3647 commit 354fbee
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/rrweb/test/benchmark/dom-mutation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ const suites: Array<
eval: 'window.workload()',
times: 5,
},
{
title: 'modify attributes on 10000 DOM nodes',
html: 'benchmark-dom-mutation-attributes.html',
eval: 'window.workload()',
times: 10,
},
];

function avg(v: number[]): number {
Expand Down
21 changes: 21 additions & 0 deletions packages/rrweb/test/html/benchmark-dom-mutation-attributes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<html>
<body></body>
<script>
function init() {
const count = 10000;
for (let i = 0; i < count; ++i) {
const div = document.createElement('div');
document.body.appendChild(div);
}
}

init();

window.workload = () => {
const divs = document.getElementsByTagName('div');
for (let div of divs) {
div.classList.add('foo');
}
};
</script>
</html>

0 comments on commit 354fbee

Please sign in to comment.