fix: add scoped error logging for lexer/parser errors
- Add std.log.scoped(.pugz) to template.zig and view_engine.zig - Log detailed error info (code, line, column, message) when parsing fails - Log template path context in ViewEngine on parse errors - Remove debug print from lexer, use proper scoped logging instead - Move benchmarks, docs, examples, playground, tests out of src/ to project root - Update build.zig and documentation paths accordingly - Bump version to 0.3.1
This commit is contained in:
86
benchmarks/pugjs/bench.js
Normal file
86
benchmarks/pugjs/bench.js
Normal file
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* Pug.js Benchmark - Comparison with Pugz
|
||||
*
|
||||
* Run: npm install && npm run bench
|
||||
*
|
||||
* Both Pug.js and Pugz benchmarks read from the same files:
|
||||
* ../templates/*.pug (templates)
|
||||
* ../templates/*.json (data)
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const pug = require('pug');
|
||||
|
||||
const iterations = 2000;
|
||||
const templatesDir = path.join(__dirname, '..', 'templates');
|
||||
|
||||
const benchmarks = [
|
||||
'simple-0',
|
||||
'simple-1',
|
||||
'simple-2',
|
||||
'if-expression',
|
||||
'projects-escaped',
|
||||
'search-results',
|
||||
'friends',
|
||||
];
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// Load templates and data from shared files BEFORE benchmarking
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
console.log("");
|
||||
console.log("Loading templates and data...");
|
||||
|
||||
const templates = {};
|
||||
const data = {};
|
||||
|
||||
for (const name of benchmarks) {
|
||||
templates[name] = fs.readFileSync(path.join(templatesDir, `${name}.pug`), 'utf8');
|
||||
data[name] = JSON.parse(fs.readFileSync(path.join(templatesDir, `${name}.json`), 'utf8'));
|
||||
}
|
||||
|
||||
// Compile all templates BEFORE benchmarking
|
||||
const compiled = {};
|
||||
for (const name of benchmarks) {
|
||||
compiled[name] = pug.compile(templates[name], { pretty: true });
|
||||
}
|
||||
|
||||
console.log("Templates compiled. Starting benchmark...\n");
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// Benchmark
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
console.log("╔═══════════════════════════════════════════════════════════════╗");
|
||||
console.log(`║ Pug.js Benchmark (${iterations} iterations) ║`);
|
||||
console.log("║ Templates: benchmarks/templates/*.pug ║");
|
||||
console.log("║ Data: benchmarks/templates/*.json ║");
|
||||
console.log("╚═══════════════════════════════════════════════════════════════╝");
|
||||
|
||||
let total = 0;
|
||||
|
||||
for (const name of benchmarks) {
|
||||
const compiledFn = compiled[name];
|
||||
const templateData = data[name];
|
||||
|
||||
// Warmup
|
||||
for (let i = 0; i < 100; i++) {
|
||||
compiledFn(templateData);
|
||||
}
|
||||
|
||||
// Benchmark
|
||||
const start = process.hrtime.bigint();
|
||||
for (let i = 0; i < iterations; i++) {
|
||||
compiledFn(templateData);
|
||||
}
|
||||
const end = process.hrtime.bigint();
|
||||
|
||||
const ms = Number(end - start) / 1_000_000;
|
||||
total += ms;
|
||||
console.log(` ${name.padEnd(20)} => ${ms.toFixed(1).padStart(7)}ms`);
|
||||
}
|
||||
|
||||
console.log("");
|
||||
console.log(` ${"TOTAL".padEnd(20)} => ${total.toFixed(1).padStart(7)}ms`);
|
||||
console.log("");
|
||||
Reference in New Issue
Block a user