本文整理汇总了C#中CalculationEngine.Formula方法的典型用法代码示例。如果您正苦于以下问题:C# CalculationEngine.Formula方法的具体用法?C# CalculationEngine.Formula怎么用?C# CalculationEngine.Formula使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CalculationEngine
的用法示例。
在下文中一共展示了CalculationEngine.Formula方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BenchMarkCalculationEngineRandomFunctionBuild
private static void BenchMarkCalculationEngineRandomFunctionBuild(CalculationEngine engine, List<string> functions,
int numberOfTests)
{
Random random = new Random();
DateTime start = DateTime.Now;
Parallel.ForEach(functions,(functionText)=>
{
Func<int, int, int, double> function = (Func<int, int, int, double>)engine.Formula(functionText)
.Parameter("var1", DataType.Integer)
.Parameter("var2", DataType.Integer)
.Parameter("var3", DataType.Integer)
.Result(DataType.FloatingPoint)
.Build();
for (int i = 0; i < numberOfTests; i++)
{
function(random.Next(), random.Next(), random.Next());
}
});
DateTime end = DateTime.Now;
Console.WriteLine("Total duration: {0}", end - start);
}
示例2: BenchMarkCalculationEngineFunctionBuild
private static void BenchMarkCalculationEngineFunctionBuild(CalculationEngine engine, string functionText)
{
DateTime start = DateTime.Now;
Func<int, int, int, double> function = (Func<int, int, int, double>)engine.Formula(functionText)
.Parameter("var1", DataType.Integer)
.Parameter("var2", DataType.Integer)
.Parameter("something", DataType.Integer)
.Result(DataType.FloatingPoint)
.Build();
Random random = new Random();
for (int i = 0; i < NumberOfTests; i++)
{
function(random.Next(), random.Next(), random.Next());
}
DateTime end = DateTime.Now;
Console.WriteLine("Total duration: {0}", end - start);
}
示例3: BenchMarkCalculationEngineRandomFunctionBuild
private static void BenchMarkCalculationEngineRandomFunctionBuild(CalculationEngine engine, List<string> functions,
int numberOfTests)
{
Random random = new Random();
DateTime start = DateTime.Now;
List<Task> tasks = new List<Task>();
foreach (string functionText in functions)
{
Task task = new Task(() =>
{
Func<int, int, int, double> function = (Func<int, int, int, double>)engine.Formula(functionText)
.Parameter("var1", DataType.Integer)
.Parameter("var2", DataType.Integer)
.Parameter("var3", DataType.Integer)
.Result(DataType.FloatingPoint)
.Build();
for (int i = 0; i < numberOfTests; i++)
{
function(random.Next(), random.Next(), random.Next());
}
});
tasks.Add(task);
task.Start();
}
Task.WaitAll(tasks.ToArray());
DateTime end = DateTime.Now;
Console.WriteLine("Total duration: {0}", end - start);
}
示例4: TestFormulaBuilderInvalidParameterName
public void TestFormulaBuilderInvalidParameterName()
{
AssertExtensions.ThrowsException<ArgumentException>(() =>
{
CalculationEngine engine = new CalculationEngine();
Func<int, double, double> function = (Func<int, double, double>)engine.Formula("sin+2")
.Parameter("sin", DataType.Integer)
.Build();
});
}
示例5: TestFormulaBuilderDuplicateParameterName
public void TestFormulaBuilderDuplicateParameterName()
{
AssertExtensions.ThrowsException<ArgumentException>(() =>
{
CalculationEngine engine = new CalculationEngine();
Func<int, double, double> function = (Func<int, double, double>)engine.Formula("var1+2")
.Parameter("var1", DataType.Integer)
.Parameter("var1", DataType.FloatingPoint)
.Build();
});
}
示例6: TestFormulaBuilderCompiled
public void TestFormulaBuilderCompiled()
{
CalculationEngine engine = new CalculationEngine(CultureInfo.InvariantCulture, ExecutionMode.Compiled);
Func<int, double, double> function = (Func<int, double, double>)engine.Formula("var1+2*(3*age)")
.Parameter("var1", DataType.Integer)
.Parameter("age", DataType.FloatingPoint)
.Result(DataType.FloatingPoint)
.Build();
double result = function(2, 4);
Assert.AreEqual(26.0, result);
}
示例7: TestFormulaBuilderInvalidParameterName
public void TestFormulaBuilderInvalidParameterName()
{
CalculationEngine engine = new CalculationEngine();
Func<int, double, double> function = (Func<int, double, double>)engine.Formula("sin+2")
.Parameter("sin", DataType.Integer)
.Build();
}
示例8: TestFormulaBuilderDuplicateParameterName
public void TestFormulaBuilderDuplicateParameterName()
{
CalculationEngine engine = new CalculationEngine();
Func<int, double, double> function = (Func<int, double, double>)engine.Formula("var1+2")
.Parameter("var1", DataType.Integer)
.Parameter("var1", DataType.FloatingPoint)
.Build();
}