Skip to content

Commit

Permalink
Minor tweaks to help with the https://github.com/11ty/eleventy-plugin…
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jan 16, 2022
1 parent 7655706 commit 08fe54e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/BenchmarkGroup.js
Expand Up @@ -66,6 +66,10 @@ class BenchmarkGroup {
this.minimumThresholdPercent = val;
}

has(type) {
return !!this.benchmarks[type];
}

get(type) {
if (!this.benchmarks[type]) {
this.benchmarks[type] = new Benchmark();
Expand Down
4 changes: 4 additions & 0 deletions src/BenchmarkManager.js
Expand Up @@ -29,6 +29,10 @@ class BenchmarkManager {
this.isVerbose = !!isVerbose;
}

hasBenchmarkGroup(name) {
return name in this.benchmarkGroups;
}

getBenchmarkGroup(name) {
if (!this.benchmarkGroups[name]) {
this.benchmarkGroups[name] = new BenchmarkGroup();
Expand Down
16 changes: 13 additions & 3 deletions src/TemplateContent.js
Expand Up @@ -290,9 +290,7 @@ class TemplateContent {
}

let templateBenchmark = this.bench.get("Template Compile");
let inputPathBenchmark = this.bench.get(
`> Template Compile > ${this.inputPath}`
);
let inputPathBenchmark = this.bench.get(`> Compile > ${this.inputPath}`);
templateBenchmark.before();
inputPathBenchmark.before();
let fn = await this.templateRender.getCompiledTemplate(str);
Expand Down Expand Up @@ -416,14 +414,26 @@ class TemplateContent {
let inputPathBenchmark = this.bench.get(
`> Render > ${this.inputPath}${paginationSuffix.join("")}`
);
let outputPathBenchmark;
if (data.page && data.page.outputPath) {
outputPathBenchmark = this.bench.get(
`> Render > ${data.page.outputPath}`
);
}

templateBenchmark.before();
if (inputPathBenchmark) {
inputPathBenchmark.before();
}
if (outputPathBenchmark) {
outputPathBenchmark.before();
}

let rendered = await fn(data);

if (outputPathBenchmark) {
outputPathBenchmark.after();
}
if (inputPathBenchmark) {
inputPathBenchmark.after();
}
Expand Down

0 comments on commit 08fe54e

Please sign in to comment.