Skip to content

DamianMullins/NodeServicesBenchmark

Repository files navigation

NodeServices Benchmarks

The benchmarks test the performance of using NodeServices in a .Net Core web application to compile & serve Handlebars templates versus the standard Razor templates.

Running The Benchmarks

To run the benchmarks, first clone or download the project, then run dotnet run -c release in the /NodeServicesBenchmark/NodeServicesBenchmark.BenchmarkRunner directory.

Benchmark Application

The benchmark application uses BenchmarkDotNet to run the benchmarks. The benchmarks set use a TestServer, which uses the Microsoft.AspNetCore.TestHost package, to create a test instance of the benchmark website.

There are two classes which contain benchmarks; LoopBenchmarks.cs and RandomLoopBenchmarks.cs, these call out to the routes described in the Web App Details section.

Web App Details

In the web project there are six routes with the following in each:

  • Razor template with the same data each time the page is loaded
  • Handlebars template with the same data each time the page is loaded
  • Cached Handlebars template with the same data each time the page is loaded
  • Razor template with random data each time the page is loaded
  • Handlebars template with random data each time the page is loaded
  • Cached Handlebars template with random data each time the page is loaded

View Components

Both the random and non-random sets of routes are served via two view components. Each view component contains logic which decides how it is going to serve up the HTML — Razor or Handlebars.

Handlebars templates

The handlebars templates are served via NodeServices in TemplateService.cs which calls a node module called templates.js.

templates.js is a self contained, pre-bundled version of the Just Eat f-templates module which looks up Handlebars templates, partials, and resources (translations) which live in a templates directory. Because it has been pre-bundled there is no need to deploy a node_modules directory to a production server.

Node Services

Node services can be called in one of two ways

TemplateService

The TemplateService calls INodeServices.InvokeExportAsync(), passing down some options, which then returns a Handlebars template.

CachedTemplateService

The CachedTemplateService calls down to the TemplateService and then uses IMemoryCache to store the result in an in-memory cache, so any subsequent requests will return the result from the cache.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors