This is not really a benchmark, but rather a toy application to assess the performances of the library in a real world use case, versus different baselines: the same fastify application built with the popular template engines pug (the one I would use by default) and ejs(a very popular one in the community with 13M weekly downloads).
The application is a blog page where posts are loaded from a fake database. To simulate some latency we run the following code:
const LATENCY = env.DB_LATENCY || 10;
export async function getPosts() {
const latency = Math.round(Math.random() * LATENCY);
await setTimeout(latency);
return [...postList];
}
Then, we run autocannon to see how many requests the server can process.
On my machine, I get the following results (median requests by second):
tpl-stream | pug | ejs |
---|---|---|
1550 | 1632 | 670 |
tpl-stream
is more than capable and I will use it as my default template engine from now.