diff --git a/benchmark/cross-engines.js b/benchmark/cross-engines.js index dd9cbab6c..7b2567daf 100755 --- a/benchmark/cross-engines.js +++ b/benchmark/cross-engines.js @@ -5,8 +5,8 @@ const data = require('./data/todolist.json') const path = require('path') const engines = { - liquid: require('./engines/liquid'), handlebars: require('./engines/handlebars'), + liquid: require('./engines/liquid'), react: require('./engines/react'), swig: require('./engines/swig') } diff --git a/benchmark/diff.js b/benchmark/diff.js new file mode 100755 index 000000000..22c38b702 --- /dev/null +++ b/benchmark/diff.js @@ -0,0 +1,47 @@ +#!/usr/bin/env node +const { performance } = require('perf_hooks') +const path = require('path') + +const FILE_LOCAL = process.argv[2] +const FILE_LATEST = process.argv[3] +console.log(`Local: ${FILE_LOCAL}`) +console.log(`Latest: ${FILE_LATEST}`) + +const { createEngine } = require('./engines/create-liquid') +const local = createEngine(require(path.resolve(__dirname, '..', FILE_LOCAL))) +const latest = createEngine(require(path.resolve(__dirname, '..', FILE_LOCAL))) +const data = require('./data/todolist.json') +const tpl = path.resolve(__dirname, `templates/todolist`) + +const begin = performance.now() +const tplLocal = local.load(tpl) +const tplLatest = latest.load(tpl) +const tasks = [ + { + cycles: 0, + time: 0, + fn: () => latest.render(tplLatest, data) + }, + { + cycles: 0, + time: 0, + fn: () => local.render(tplLocal, data) + } +] +while (performance.now() - begin < 20e3) { + const task = tasks[Math.floor(Math.random() * 2)] + task.time -= performance.now() + task.fn() + task.time += performance.now() + task.cycles++ +} + +const [ latestResult, localResult ] = tasks.map(task => { + task.perf = task.cycles * 1000 / task.time + return task +}) +const diff = (localResult.perf - latestResult.perf) / latestResult.perf + +console.log(`Local: ${localResult.perf.toFixed(3)} ops/s (${localResult.cycles} cycles)`) +console.log(`Latest: ${latestResult.perf.toFixed(3)} ops/s (${latestResult.cycles} cycles)`) +console.log(`Diff: ${(diff * 100).toFixed(3)}%`) diff --git a/benchmark/engines/create-liquid.js b/benchmark/engines/create-liquid.js new file mode 100644 index 000000000..59b01f384 --- /dev/null +++ b/benchmark/engines/create-liquid.js @@ -0,0 +1,17 @@ +const { readFileSync } = require('fs') +const { join } = require('path') + +function createEngine (pkg) { + const liquid = new pkg.Liquid({ + root: join(__dirname, '../templates'), + cache: true, + extname: '.liquid' + }) + liquid.registerFilter('url', path => `http://example.com${path}`) + return { + load: path => liquid.parse(readFileSync(path + '.liquid', 'utf8')), + render: (tpl, data) => liquid.renderSync(tpl, data) + } +} + +module.exports = { createEngine } diff --git a/benchmark/engines/liquid.js b/benchmark/engines/liquid.js index 4a1a9e6be..eb623540b 100644 --- a/benchmark/engines/liquid.js +++ b/benchmark/engines/liquid.js @@ -1,16 +1,3 @@ -const { Liquid } = require('../..') -const { readFileSync } = require('fs') -const { join } = require('path') +const { createEngine } = require('./create-liquid') -const liquid = new Liquid({ - root: join(__dirname, '../templates'), - cache: true, - extname: '.liquid' -}) - -liquid.registerFilter('url', path => `http://example.com${path}`) - -module.exports = { - load: path => liquid.parse(readFileSync(path + '.liquid', 'utf8')), - render: (tpl, data) => liquid.renderSync(tpl, data) -} +module.exports = createEngine(require('../../dist/liquid.node.cjs')) diff --git a/bin/perf-diff.sh b/bin/perf-diff.sh new file mode 100755 index 000000000..fbd1cb9aa --- /dev/null +++ b/bin/perf-diff.sh @@ -0,0 +1,16 @@ +#!/usr/bin/bash + +VERSION_LATEST=$(cat package.json | grep '"version":' | awk -F'"' '{print $4}') +FILE_LOCAL=dist/liquid.node.cjs.js +FILE_LATEST=dist/liquid.node.cjs.$VERSION_LATEST.js +URL_LATEST=https://unpkg.com/liquidjs@$VERSION_LATEST/dist/liquid.node.cjs.js + +if [ ! -f $FILE_LATEST ]; then + curl $URL_LATEST > $FILE_LATEST +fi + +if [ ! -f $FILE_LOCAL ]; then + BUNDLES=cjs npm run build:dist +fi + +node benchmark/diff.js $FILE_LOCAL $FILE_LATEST diff --git a/dist/.gitignore b/dist/.gitignore new file mode 100644 index 000000000..e69de29bb diff --git a/docs/themes/navy/layout/partial/all-contributors.swig b/docs/themes/navy/layout/partial/all-contributors.swig index bf790a0e8..5520166ed 100644 --- a/docs/themes/navy/layout/partial/all-contributors.swig +++ b/docs/themes/navy/layout/partial/all-contributors.swig @@ -45,6 +45,8 @@