mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
chore: perf diff against latest release
This commit is contained in:
@@ -5,8 +5,8 @@ const data = require('./data/todolist.json')
|
|||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
const engines = {
|
const engines = {
|
||||||
liquid: require('./engines/liquid'),
|
|
||||||
handlebars: require('./engines/handlebars'),
|
handlebars: require('./engines/handlebars'),
|
||||||
|
liquid: require('./engines/liquid'),
|
||||||
react: require('./engines/react'),
|
react: require('./engines/react'),
|
||||||
swig: require('./engines/swig')
|
swig: require('./engines/swig')
|
||||||
}
|
}
|
||||||
|
|||||||
Executable
+47
@@ -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)}%`)
|
||||||
@@ -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 }
|
||||||
@@ -1,16 +1,3 @@
|
|||||||
const { Liquid } = require('../..')
|
const { createEngine } = require('./create-liquid')
|
||||||
const { readFileSync } = require('fs')
|
|
||||||
const { join } = require('path')
|
|
||||||
|
|
||||||
const liquid = new Liquid({
|
module.exports = createEngine(require('../../dist/liquid.node.cjs'))
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|||||||
Executable
+16
@@ -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
|
||||||
@@ -45,6 +45,8 @@
|
|||||||
<td align="center"><a href="https://github.com/ilhamdev0"><img src="https://avatars.githubusercontent.com/u/57636145?v=4?s=100" width="100px;" alt=""/></a></td>
|
<td align="center"><a href="https://github.com/ilhamdev0"><img src="https://avatars.githubusercontent.com/u/57636145?v=4?s=100" width="100px;" alt=""/></a></td>
|
||||||
<td align="center"><a href="https://github.com/c412216887"><img src="https://avatars.githubusercontent.com/u/29691650?v=4?s=100" width="100px;" alt=""/></a></td>
|
<td align="center"><a href="https://github.com/c412216887"><img src="https://avatars.githubusercontent.com/u/29691650?v=4?s=100" width="100px;" alt=""/></a></td>
|
||||||
<td align="center"><a href="https://digitalinspiration.com/"><img src="https://avatars.githubusercontent.com/u/1344071?v=4?s=100" width="100px;" alt=""/></a></td>
|
<td align="center"><a href="https://digitalinspiration.com/"><img src="https://avatars.githubusercontent.com/u/1344071?v=4?s=100" width="100px;" alt=""/></a></td>
|
||||||
|
<td align="center"><a href="https://n1ru4l.cloud/"><img src="https://avatars.githubusercontent.com/u/14338007?v=4?s=100" width="100px;" alt=""/></a></td>
|
||||||
|
<td align="center"><a href="https://github.com/mattvague"><img src="https://avatars.githubusercontent.com/u/64985?v=4?s=100" width="100px;" alt=""/></a></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -14,7 +14,9 @@
|
|||||||
"lint": "eslint \"**/*.ts\" .",
|
"lint": "eslint \"**/*.ts\" .",
|
||||||
"check": "npm test && npm run lint",
|
"check": "npm test && npm run lint",
|
||||||
"test": "nyc mocha \"test/**/*.ts\"",
|
"test": "nyc mocha \"test/**/*.ts\"",
|
||||||
"benchmark": "cd benchmark && npm ci && npm start",
|
"perf": "cd benchmark && npm ci && npm start",
|
||||||
|
"perf:diff": "bin/perf-diff.sh",
|
||||||
|
"perf:engines": "cd benchmark && npm run engines",
|
||||||
"build": "npm run build:dist && npm run build:docs",
|
"build": "npm run build:dist && npm run build:docs",
|
||||||
"build:dist": "rm -rf dist && rollup -c rollup.config.ts && ls -lh dist",
|
"build:dist": "rm -rf dist && rollup -c rollup.config.ts && ls -lh dist",
|
||||||
"build:docs": "bin/build-docs.sh"
|
"build:docs": "bin/build-docs.sh"
|
||||||
|
|||||||
Reference in New Issue
Block a user