Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
N

NCalc2

> 后端框架
Open source

expression evaluator for .NET with built-in compiler

187 stars0 likes2 views
WebsiteGitHub

About

expression evaluator for .NET with built-in compiler

NCalc

:warning: This repository was merged with https://github.com/ncalc/ncalc. Please switch to that package as this repository will only exist as an archive.

A clone of NCalc from http://ncalc.codeplex.com/ with the following changes:

  • added support for .NET Standard 2.0+
  • added compilation of expressions to actual CLR lambdas

Installation

Simply install the package via NuGet

powershell
PM> Install-Package CoreCLR-NCalc

Creating Lambdas

Simple Expressions

csharp
var expr = new Expression("1 + 2");
Func f = expr.ToLambda();
Console.WriteLine(f()); // will print 3

Expressions with Functions and Parameters

csharp
class ExpressionContext
{
  public int Param1 { get; set; }
  public string Param2 { get; set; }
  
  public int Foo(int a, int b)
  {
    return a + b;
  }
}

var expr = new Expression("Foo([Param1], 2) = 4 && [Param2] = 'test'");
Func f = expr.ToLambda();

var context = new ExpressionContext { Param1 = 2, Param2 = "test" };
Console.WriteLine(f(context)); // will print True

Performance Comparison

The measurements were done during CI runs on AppVeyor and fluctuate a lot in between runs, but the speedup is consistently in the thousands of percent range. The speedup measured on actual hardware was even higher (between 10,000% and 35,000%).

Formula Description Expression Evaluations / sec Lambda Evaluations / sec Speedup
(4 * 12 / 7) + ((9 * 2) % 8) Simple Arithmetics 474,247.87 32,691,490.41 6,793.33%
5 * 2 = 2 * 5 && (1 / 3.0) * 3 = 1 Simple Arithmetics 276,226.31 93,222,709.05 33,648.67%
[Param1] * 7 + [Param2] Constant Values 707,493.27 21,766,101.47 2,976.51%
[Param1] * 7 + [Param2] Dynamic Values 582,832.10 21,400,445.13 3,571.80%
Foo([Param1] * 7, [Param2]) Dynamic Values and Function Call 594,259.69 17,209,334.34 2,795.93%

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C#c-sharpdotnet-coredotnet-standarddotnetcore

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category后端框架
PricingOpen source

> Related tools

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架