Skip to content

Commit

Permalink
add more perf tests
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Sep 6, 2022
1 parent 46db9e5 commit f723f5c
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Router.map(function () {
this.route('relationship-materialization-simple');
this.route('relationship-materialization-complex');
this.route('add-children');
this.route('add-children-then-materialize');
this.route('add-children-to-materialized');
this.route('unload');
this.route('unload-all');
this.route('destroy');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default Route.extend({
store: service(),

async model() {
performance.mark('start-data-generation');

const initialPayload = await fetch('./fixtures/add-children-initial.json').then((r) => r.json());
const updatePayload = await fetch('./fixtures/add-children-final.json').then((r) => r.json());

performance.mark('start-push-initial-payload');
this.store.push(initialPayload);

performance.mark('start-push-update-payload');
this.store.push(updatePayload);

performance.mark('start-materialize-records');
const peekedParents = this.store.peekAll('parent').slice();
this.store.peekAll('child').slice();

performance.mark('start-materialize-relationships');
let seen = new Set();
peekedParents.forEach((parent) => iterateParent(parent, seen));

performance.mark('end-materialize-relationships');
},
});

function iterateChild(record, seen) {
if (seen.has(record)) {
return;
}
seen.add(record);
// record.parent.get('name');
record.bestFriend.get('name');
record.secondBestFriend.get('name');
record.friends.forEach((child) => iterateChild(child, seen));
}
function iterateParent(record, seen) {
seen.add(record);
record.children.forEach((child) => iterateChild(child, seen));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default Route.extend({
store: service(),

async model() {
performance.mark('start-data-generation');

const initialPayload = await fetch('./fixtures/add-children-initial.json').then((r) => r.json());
const updatePayload = await fetch('./fixtures/add-children-final.json').then((r) => r.json());

performance.mark('start-push-initial-payload');
this.store.push(initialPayload);

performance.mark('start-initial-materialize-records');
let peekedParents = this.store.peekAll('parent').slice();
this.store.peekAll('child').slice();

performance.mark('start-initial-materialize-relationships');
let seen = new Set();
peekedParents.forEach((parent) => iterateParent(parent, seen));

performance.mark('start-push-update-payload');
this.store.push(updatePayload);

performance.mark('start-materialize-all-records');
peekedParents = this.store.peekAll('parent').slice();
this.store.peekAll('child').slice();

performance.mark('start-materialize-all-relationships');
seen = new Set();
peekedParents.forEach((parent) => iterateParent(parent, seen));

performance.mark('end-materialize-all-relationships');
},
});

function iterateChild(record, seen) {
if (seen.has(record)) {
return;
}
seen.add(record);
// record.parent.get('name');
record.bestFriend.get('name');
record.secondBestFriend.get('name');
record.friends.forEach((child) => iterateChild(child, seen));
}
function iterateParent(record, seen) {
seen.add(record);
record.children.forEach((child) => iterateChild(child, seen));
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
<li><LinkTo @route='unload-all'>Unload All</LinkTo></li>
<li><LinkTo @route='destroy'>Destroy</LinkTo></li>
<li><LinkTo @route='add-children'>Add Children</LinkTo></li>
<li><LinkTo @route='add-children-to-materialized'>Add Children To Materialized</LinkTo></li>
<li><LinkTo @route='add-children-then-materialize'>Add Children Then Materialize</LinkTo></li>
<li><LinkTo @route='unused-relationships'>Unused Relationships</LinkTo></li>
</ol>

0 comments on commit f723f5c

Please sign in to comment.