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
Changes from 6 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",
9 changes: 6 additions & 3 deletions module/classes/DevModeConfig.mjs
Original file line number Diff line number Diff line change
@@ -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, {
@@ -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;
9 changes: 6 additions & 3 deletions module/classes/DevModePerformance.mjs
Original file line number Diff line number Diff line change
@@ -17,14 +17,17 @@ export class DevModePerformance {
});
}

static actorCRUDTest = async (iterations = 1000) => {
console.log('running test with iterations:', `${iterations}`, !!iterations, iterations || 1000);
static actorCRUDTest = async (type, iterations = 1000) => {
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
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 });
12 changes: 9 additions & 3 deletions templates/settings.hbs
Original file line number Diff line number Diff line change
@@ -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>