Skip to content

Commit

Permalink
Fix and improve crud test (#42)
Browse files Browse the repository at this point in the history
* Make CRUD setting fetching easily extensible

* Add actor type selection

* Add synthetic option, default to enabled

* Touchup

* Pass arguments as object

* Remove synthetic option.

Foundry doesn't like .update() on synthetic actors

* Apply suggested changes
  • Loading branch information
mkahvi authored Apr 5, 2022
1 parent 8de072a commit 5562d8f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
9 changes: 6 additions & 3 deletions module/classes/DevModeConfig.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ export class DevModeConfig extends FormApplication {
packageSpecificDebugFormData,
debugOverrideFormData,
overrideConfigDebug: game.settings.get(DevMode.MODULE_ID, DevMode.SETTINGS.overrideConfigDebug),
actorTypes: game.system.template.Actor.types.reduce((types, type) => {
types[type] = `ACTOR.Type${type.capitalize()}`;
return types;
}, {}),
};

DevMode.log(false, data, {
Expand All @@ -191,9 +195,8 @@ export class DevModeConfig extends FormApplication {

switch (event.currentTarget?.dataset?.action) {
case 'actorCRUD': {
const inputVal = html.find('input[name="actorCrudIterations"]').val();
console.log('inputVal', inputVal);
return DevModePerformance.actorCRUDTest(inputVal || undefined);
const formData = expandObject(new FormDataExtended(event.currentTarget.closest('form')).toObject());
return DevModePerformance.actorCRUDTest(formData.actorCrud);
}
default:
return;
Expand Down
7 changes: 4 additions & 3 deletions module/classes/DevModePerformance.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ export class DevModePerformance {
});
}

static actorCRUDTest = async (iterations = 1000) => {
console.log('running test with iterations:', `${iterations}`, !!iterations, iterations || 1000);
static actorCRUDTest = async ({ type, iterations = 1000 } = {}) => {
if (!game.system.template.Actor.types.includes(type)) return console.error(type, "is invalid actor type");
console.log(`Running CRUD test on "${type}" type with ${iterations} iterations`);
const debugConfig = { ...CONFIG.debug };
this.resetDebug();

const now = performance.now();
for (let x = 0; x <= iterations; x++) {
const created = await Actor.create({ name: `${x}`, type: 'npc' });
const created = await Actor.create({ name: `${x}`, type });
await created.update({ name: 'Actor' + x });
await created.delete();
if (x % 10 == 0) SceneNavigation.displayProgressBar({ label: 'Test Progress', pct: Math.roundDecimals((x / iterations) * 100, 1) });
Expand Down
12 changes: 9 additions & 3 deletions templates/settings.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,18 @@
<section class='tab' data-tab='performance'>
<p class="notes">{{localize 'DEV.configMenu.performance.hint'}}</p>

<h2>{{localize
'DEV.configMenu.performance.actorCRUD.label'}}</h2>
<h2>{{localize 'DEV.configMenu.performance.actorCRUD.label'}}</h2>
<div class='flexrow form-group'>
<label>{{localize "Type"}}</label>
<select name='actorCrud.type' data-dtype='String'>
{{selectOptions actorTypes localize=true}}
</select>
</div>
<div class="flexrow form-group">
<label class="flexrow flex3" style="gap: 1em">
{{localize 'DEV.iterations'}}
<input type="number" name="actorCrudIterations" placeholder="1000" class="form-fields">
<input type="number" data-dtype="Number" min="1" step="1" name="actorCrud.iterations" placeholder="1000"
class="form-fields">
</label>
<button class="perf-action" data-action="actorCRUD">{{localize "DEV.configMenu.performance.run"}}</button>
</div>
Expand Down

0 comments on commit 5562d8f

Please sign in to comment.