-
-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: perf diff against latest release
- Loading branch information
Showing
8 changed files
with
88 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)}%`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters