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 4 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
1 change: 1 addition & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"DEV": {
"iterations": "Iterations",
"synthetic": "Synthetic",
"clipboard": {
"copy": "Copy to Clipboard",
"success": "Copied to Clipboard",
Expand Down
13 changes: 10 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,12 @@ 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 form = new FormDataExtended(event.currentTarget.closest('form')).toObject();
const actorType = form.actorCrudType;
const iterations = form.actorCrudIterations;
const synthetic = form.actorCrudSynthetic;
console.log('CRUD', { actorType, iterations, synthetic });
return DevModePerformance.actorCRUDTest(actorType, iterations || undefined, synthetic);
mkahvi marked this conversation as resolved.
Show resolved Hide resolved
}
default:
return;
Expand Down
10 changes: 7 additions & 3 deletions module/classes/DevModePerformance.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ export class DevModePerformance {
});
}

static actorCRUDTest = async (iterations = 1000) => {
console.log('running test with iterations:', `${iterations}`, !!iterations, iterations || 1000);
static actorCRUDTest = async (type, iterations = 1000, synthetic) => {
mkahvi marked this conversation as resolved.
Show resolved Hide resolved
if (!game.system.template.Actor.types.includes(type)) return console.error(type, "is invalid actor type");
// Force some defaults
iterations ||= 1000;
mkahvi marked this conversation as resolved.
Show resolved Hide resolved
synthetic ??= true;
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 }, { temporary: synthetic });
await created.update({ name: 'Actor' + x });
await created.delete();
if (x % 10 == 0) SceneNavigation.displayProgressBar({ label: 'Test Progress', pct: (x / iterations) * 100 });
Expand Down
16 changes: 13 additions & 3 deletions templates/settings.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,25 @@
<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='actorCrudType' 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="actorCrudIterations" placeholder="1000"
class="form-fields">
</label>
<button class="perf-action" data-action="actorCRUD">{{localize "DEV.configMenu.performance.run"}}</button>
</div>
<div class="flexrow form-group">
<input type='checkbox' data-dtype='Boolean' checked=true>
<label>{{localize 'DEV.synthetic'}}</label>
</div>
<p class="notes">{{localize 'DEV.configMenu.performance.actorCRUD.hint'}}</p>
</section>
</div>
Expand Down