- Add two benchmark modes: cached AST (render only) and no cache (parse+render) - Shows parse overhead is 69.2% of total time (331ms out of 478ms) - Fix use-after-free in ViewEngine.processIncludes by transferring child ownership - Fix memory leaks by using ArenaAllocator pattern in test_includes - Update test expectations to match actual template content (mixins, not partials) - All tests pass Benchmark results (2000 iterations): - Cached (render only): 147.3ms - No cache (parse+render): 478.3ms - Parse overhead: 331.0ms (3.2x slower without caching)
38 lines
1.2 KiB
Zig
38 lines
1.2 KiB
Zig
const std = @import("std");
|
|
const pugz = @import("pugz");
|
|
|
|
pub fn main() !void {
|
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
|
defer _ = gpa.deinit();
|
|
const allocator = gpa.allocator();
|
|
|
|
// Use ArenaAllocator for ViewEngine (recommended pattern)
|
|
var arena = std.heap.ArenaAllocator.init(allocator);
|
|
defer arena.deinit();
|
|
const arena_alloc = arena.allocator();
|
|
|
|
// Test: Simple include from test_views
|
|
var engine = pugz.ViewEngine.init(.{
|
|
.views_dir = "tests/sample/01",
|
|
});
|
|
defer engine.deinit();
|
|
|
|
const html = engine.render(arena_alloc, "home", .{}) catch |err| {
|
|
std.debug.print("Error: {}\n", .{err});
|
|
return err;
|
|
};
|
|
|
|
std.debug.print("=== Rendered HTML ===\n{s}\n=== End ===\n", .{html});
|
|
|
|
// Verify output contains mixin-generated content
|
|
if (std.mem.indexOf(u8, html, "card") != null and
|
|
std.mem.indexOf(u8, html, "Title") != null and
|
|
std.mem.indexOf(u8, html, "content here") != null)
|
|
{
|
|
std.debug.print("\nSUCCESS: Include and mixin directives work correctly!\n", .{});
|
|
} else {
|
|
std.debug.print("\nFAILURE: Expected content not found!\n", .{});
|
|
return error.TestFailed;
|
|
}
|
|
}
|