mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 12:20:40 -07:00
Checking for file existence is unnecessary when cache contains entry.
37 lines
919 B
TypeScript
37 lines
919 B
TypeScript
import * as Benchmark from 'benchmark'
|
|
import Liquid from '../src/liquid'
|
|
|
|
const engineOptions = {
|
|
root: __dirname,
|
|
extname: '.liquid'
|
|
}
|
|
|
|
const engine = new Liquid(engineOptions)
|
|
const cachingEngine = new Liquid({
|
|
...engineOptions,
|
|
cache: true
|
|
})
|
|
|
|
const template = `
|
|
{% layout "./templates/layout.liquid" %}
|
|
{% block body %}a small body{% endblock %}
|
|
`
|
|
|
|
export default function () {
|
|
console.log('--- layout ---')
|
|
return new Promise(resolve => {
|
|
new Benchmark.Suite('layout')
|
|
.add('cache=false', {
|
|
defer: true,
|
|
fn: (d: any) => engine.parseAndRender(template, {}).then(x => d.resolve(x))
|
|
})
|
|
.add('cache=true', {
|
|
defer: true,
|
|
fn: (d: any) => cachingEngine.parseAndRender(template, {}).then(x => d.resolve(x))
|
|
})
|
|
.on('cycle', (event: any) => console.log(String(event.target)))
|
|
.on('complete', resolve)
|
|
.run({ 'async': true })
|
|
})
|
|
}
|