Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and improve crud test #42

Merged
merged 7 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions module/classes/DevModeConfig.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,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 @@ -188,9 +192,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: (x / iterations) * 100 });
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