Stack Exchange
evaluate dynamically created formula on large (in memory) flat table
I am currently using this code:
using System;
using NCalc;

namespace SandboxConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            double[,] data = new double[100, 10];
            Random random = new Random();

            var numberOfRows = data.GetLength(0);
            var numberOfColumns = data.GetLength(1);

            for (int row = 0; row < numberOfRows; row++)
            {
                for (int col = 0; col < numberOfColumns; col++)
                {
                    data[row, col] = random.Next();
                }
            }

            // in the case of 10 columns the expression looks like: [x0] + [x1] + [x2] + [x3] + [x4] + [x5] + [x6] + [x7] + [x8] + [x9]
            var stringExpression = "";
            for (int col = 0; col < numberOfColumns - 1; col++)
            {
                stringExpression += string.Format("[x{0}] + ", col);
            }
            stringExpression += string.Format("[x{0}]", (numberOfColumns - 1));

            var exp = new Expression(stringExpression);
            var total = 0.0;

            for (int row = 0; row < numberOfRows; row++)
            {
                for (int col = 0; col < numberOfColumns; col++)
                {
                    exp.Parameters[string.Format("x{0}", col)] = data[row, col];
                }

                if (row % 100000 == 0)
                {
                    Console.WriteLine(row);
                }

                if (!exp.HasErrors())
                {
                    total += (double)exp.Evaluate();
                }
            }
        } 
    }
}

Here the fake 'dynamic' expression/formula:
[x0] + [x1] + [x2] + [x3] + [x4] + [x5] + [x6] + [x7] + [x8] + [x9]

adds 10 columns of a 10000000 row 'flat file'. The execution is not very fast and I hit limits, if I have lets say 100 million rows. Is there anything I can do to execute the above faster or should I use some other technologies to execute dynamically created formulas like this? Not sure how fast MySql would be - here I would generate the formula as SQL to the db via (e.g. Dapper). 

Did you compare this with perfomance of direct evaluation, without NCalc? Is direct perfomance good enough?

You would have to write a parser to do this. That's why I use NCalc.

Yes I understand, but I mean it's just interesting to know which effect NCalc has on this, so I asked how much faster this code will run without NCalc.

Ok will try to hardcode and check
