Code Monkey home page Code Monkey logo

kentaasvang.templatingengine's Introduction

πŸ†• TemplatingEngine

❓ What is My Project?

A toy implementation of a naive text templating engine

I needed a simple template engine and thought this was a suitable project to learn some nuget-package maintenance and tooling. This project will probably grow over time, but it's implementation with regards to efficiency and memory-usage will be dependent on my personal need - or if I feel I wanna satisfy my curiosity and dive into optimization.

⚑ Simple Example

TemplateEngine templateEngine = new();
string template = "I love [color] [vegetable] in the [tod]";
Dictionary<string, string> keyVals = new()
{
    {"color": "red"},
    {"vegetable": "potatoes"},
    {"tod": "morning"}
};

template.LoadTemplate(template);
var result = template.Replace(keyVals);
Console.WriteLine(result);
// "I love red potatoes in the morning"

Benchmarks

// * Summary *

BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19044.1826 (21H2)
Intel Core i7-7700HQ CPU 2.80GHz (Kaby Lake), 1 CPU, 8 logical and 4 physical cores
.NET SDK=6.0.202
  [Host]     : .NET 6.0.4 (6.0.422.16404), X64 RyuJIT
  DefaultJob : .NET 6.0.4 (6.0.422.16404), X64 RyuJIT


|  Method |     Mean |   Error |   StdDev |   Median |  Gen 0 | Allocated |
|-------- |---------:|--------:|---------:|---------:|-------:|----------:|
| Replace | 392.5 ns | 7.83 ns | 20.21 ns | 385.1 ns | 0.2623 |     824 B |

// * Legends *
  Mean      : Arithmetic mean of all measurements
  Error     : Half of 99.9% confidence interval
  StdDev    : Standard deviation of all measurements
  Median    : Value separating the higher half of all measurements (50th percentile)
  Gen 0     : GC Generation 0 collects per 1000 operations
  Allocated : Allocated memory per single operation (managed only, inclusive, 1KB = 1024B)
  1 ns      : 1 Nanosecond (0.000000001 sec)

🀝 Collaborate with My Project

If you have nothing better to do, sure. Fork -> checkout new branch -> commit changes -> PR

kentaasvang.templatingengine's People

Watchers

James Cloos avatar Kent Martin Γ…svang avatar

kentaasvang.templatingengine's Issues

Support models

It's tedious to build dictionaries for keyword-values - Would be a lot simpler to just pass in a class/record

optimalizations

.NET 7 comes with new low-level struct optimizations that might be cool to use to optimize the template-engine in terms of memory-usage

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.