Esempio n. 1
0
        void registerVariables(CBatch_detail_aa_twofold current_row)
        {
            parser = new MathParserNet.Parser();

            // --- register functions
            parser.RegisterCustomDoubleFunction("deter_dilu", Deter_Dilu);

            // --- register variables
            //parser.AddVariable("", Convert.ToDouble());

            parser.AddVariable("weight1", Convert.ToDouble(current_row.Weight1));
            parser.AddVariable("weight2", Convert.ToDouble(current_row.Weight2));
            parser.AddVariable("volumen1", Convert.ToDouble(current_row.Volumen1));
            parser.AddVariable("volumen2", Convert.ToDouble(current_row.Volumen2));

            if (current_row.Reading1 != null && current_row.Reading1.Trim() != "")
            {
                parser.AddVariable("reading1", current_row.Reading1);
            }
            else
            {
                parser.AddVariable("reading1", 0);
            }

            if (current_row.Reading2 != null && current_row.Reading2.Trim() != "")
            {
                parser.AddVariable("reading2", current_row.Reading2);
            }
            else
            {
                parser.AddVariable("reading2", 0);
            }

            parser.AddVariable("dilu2", Convert.ToDouble(current_row.Dilu2));
            parser.AddVariable("dilu3", Convert.ToDouble(current_row.Dilu3));

            parser.AddVariable("flag_dilu2", Convert.ToDouble(current_row.Flag_dilu2));
            parser.AddVariable("flag_dilu3", Convert.ToDouble(current_row.Flag_dilu3));

            parser.AddVariable("fum", Convert.ToDouble(current_row.Fum));

            parser.AddVariable("calc_dilu2", "deter_dilu(dilu2, flag_dilu2)");
            parser.AddVariable("calc_dilu3", "deter_dilu(dilu3, flag_dilu3)");

            parser.AddVariable("factor1", "volumen1/weight1*calc_dilu2*calc_dilu3*fum");
            parser.AddVariable("factor2", "volumen2/weight2*calc_dilu2*calc_dilu3*fum");

            parser.AddVariable("law1", "reading1*factor1");
            parser.AddVariable("law2", "reading2*factor2");

            parser.AddVariable("Result_analysis", "(law1+law2)/2");

            AssignValues(current_row);
        }
Esempio n. 2
0
        static void RunBenchmark(BenchmarkKind which)
        {
            var yamp       = YAMP.Parser.PrimaryContext;
            var mpparser   = new MathParser.Parser();
            var mptk       = new MathParserTK_NET.MathParserTK();
            var mpnet      = new MathParserNet.Parser();
            var mfmp       = new MathFunctions.MathParser();
            var llmp       = new MathParserDataStructures.MathObj();
            var calcEngine = new CalcEngine.CalcEngine();

            calcEngine.CacheExpressions = false;

            var lines = new string[0];

            switch (which)
            {
            case BenchmarkKind.Standard:
                //         UB
                //YAMP  : 154 ms
                //LLMP  : 108 ms
                //MP    : 4134 ms
                //MPTK  : 375 ms
                //MPNET : 3054 ms
                //MFP   : 88 ms
                //CALEN : 33 ms
                //NCALC : 420 ms
                lines = MakeTenK("2-3*5+7/2-8*2");
                break;

            case BenchmarkKind.File:
                //         UB
                //YAMP  : 2084 ms
                //LLMP  : 1072 ms
                //MP    : 372847 ms
                //MPTK  : ---
                //MPNET : ---
                //MFP   : ---
                //CALEN : 271 ms
                //NCALC : ---
                if (!File.Exists(BMK_FILE))
                {
                    GenerateBenchmarks();
                }

                lines = File.ReadAllLines(BMK_FILE);
                break;

            case BenchmarkKind.Little:
                //         UB
                //YAMP  : 71 ms
                //LLMP  : 59 ms
                //MP    : 1840 ms
                //MPTK  : 87 ms
                //MPNET : 3232 ms
                //MFP   : 37 ms
                //CALEN : 23 ms
                //NCALC : 247 ms
                lines = MakeTenK("2+3");
                break;

            case BenchmarkKind.Thomson:
                //         UB
                //YAMP  : 193 ms
                //LLMP  : 138 ms
                //MP    : 11508 ms
                //MPTK  : 647 ms
                //MPNET : 3827 ms
                //MFP   : ---
                //CALEN : 41 ms
                //NCALC : ---
                lines = MakeTenK("2-(3*5)^2+7/(2-8)*2");
                break;
            }

            Console.WriteLine("Starting benchmarks ...");
            Console.WriteLine("----------");

            // The implementation here... YAMP
            Benchmark("YAMP", lines, query => yamp.Run(query));

            //http://www.codeproject.com/Articles/53001/LL-Mathematical-Parser
            Benchmark("LLMathParser", lines, query => llmp.Evaluate(query, new char[0], new double[0]));

            //http://www.codeproject.com/Articles/11164/Math-Parser
            Benchmark("MathParser", lines, query => mpparser.Evaluate(query));

            //http://www.codeproject.com/Tips/381509/Math-Parser-NET-Csharp
            Benchmark("MathParserTK", lines, query => mptk.Parse(query, false));

            //http://www.codeproject.com/Articles/274093/Math-Parser-NET
            Benchmark("MathParserNet", lines, query => mpnet.Simplify(query));

            //http://www.codeproject.com/Articles/23061/MathParser-Math-Formula-Parser
            Benchmark("MathFormulaParser", lines, query => mfmp.Calculate(query));

            //http://www.codeproject.com/Articles/246374/A-Calculation-Engine-for-NET
            Benchmark("CalcEngine", lines, query => calcEngine.Evaluate(query));

            //http://ncalc.codeplex.com/
            //Benchmark("NCalc", lines, query => new NCalc.Expression(query, NCalc.EvaluateOptions.NoCache).Evaluate());
        }
Esempio n. 3
0
        void registerVariables(CBatch_detail_aa_twofold current_row)
        {
            parser = new MathParserNet.Parser();

            // --- register functions
            parser.RegisterCustomDoubleFunction("deter_dilu", Deter_Dilu);

            // --- register variables
            //parser.AddVariable("", Convert.ToDouble());

            parser.AddVariable("weight1", Convert.ToDouble(current_row.Weight1));
            parser.AddVariable("weight2", Convert.ToDouble(current_row.Weight2));
            parser.AddVariable("volumen1", Convert.ToDouble(current_row.Volumen1));
            parser.AddVariable("volumen2", Convert.ToDouble(current_row.Volumen2));

            if (current_row.Reading1 != null && current_row.Reading1.Trim() != "")
                parser.AddVariable("reading1", current_row.Reading1);
            else
                parser.AddVariable("reading1", 0);

            if (current_row.Reading2 != null && current_row.Reading2.Trim() != "")
                parser.AddVariable("reading2", current_row.Reading2);
            else
                parser.AddVariable("reading2", 0);

            parser.AddVariable("dilu2", Convert.ToDouble(current_row.Dilu2));
            parser.AddVariable("dilu3", Convert.ToDouble(current_row.Dilu3));

            parser.AddVariable("flag_dilu2", Convert.ToDouble(current_row.Flag_dilu2));
            parser.AddVariable("flag_dilu3", Convert.ToDouble(current_row.Flag_dilu3));

            parser.AddVariable("fum", Convert.ToDouble(current_row.Fum));

            parser.AddVariable("calc_dilu2", "deter_dilu(dilu2, flag_dilu2)");
            parser.AddVariable("calc_dilu3", "deter_dilu(dilu3, flag_dilu3)");

            parser.AddVariable("factor1", "volumen1/weight1*calc_dilu2*calc_dilu3*fum");
            parser.AddVariable("factor2", "volumen2/weight2*calc_dilu2*calc_dilu3*fum");

            parser.AddVariable("law1", "reading1*factor1");
            parser.AddVariable("law2", "reading2*factor2");

            parser.AddVariable("Result_analysis", "(law1+law2)/2");

            AssignValues(current_row);
        }
Esempio n. 4
0
        static void RunBenchmark(BenchmarkKind which)
        {
            var yamp = new YAMP.Parser();
            var mpparser = new MathParser.Parser();
            var mptk = new MathParserTK_NET.MathParserTK();
            var mpnet = new MathParserNet.Parser();
            var mfmp = new MathFunctions.MathParser();
            var llmp = new MathParserDataStructures.MathObj();
            var calcEngine = new CalcEngine.CalcEngine();
            calcEngine.CacheExpressions = false;

            var lines = new string[0];

            switch (which)
            {
                case BenchmarkKind.Standard:
                    //         UB
                    //YAMP  : 154 ms
                    //LLMP  : 108 ms
                    //MP    : 4134 ms
                    //MPTK  : 375 ms
                    //MPNET : 3054 ms
                    //MFP   : 88 ms
                    //CALEN : 33 ms
                    //NCALC : 420 ms
                    lines = MakeTenK("2-3*5+7/2-8*2");
                    break;

                case BenchmarkKind.File:
                    //         UB
                    //YAMP  : 2084 ms
                    //LLMP  : 1072 ms
                    //MP    : 372847 ms
                    //MPTK  : ---
                    //MPNET : ---
                    //MFP   : ---
                    //CALEN : 271 ms
                    //NCALC : ---
                    if (!File.Exists(BMK_FILE))
                        GenerateBenchmarks();

                    lines = File.ReadAllLines(BMK_FILE);
                    break;

                case BenchmarkKind.Little:
                    //         UB
                    //YAMP  : 71 ms
                    //LLMP  : 59 ms
                    //MP    : 1840 ms
                    //MPTK  : 87 ms
                    //MPNET : 3232 ms
                    //MFP   : 37 ms
                    //CALEN : 23 ms
                    //NCALC : 247 ms
                    lines = MakeTenK("2+3");
                    break;

                case BenchmarkKind.Thomson:
                    //         UB
                    //YAMP  : 193 ms
                    //LLMP  : 138 ms
                    //MP    : 11508 ms
                    //MPTK  : 647 ms
                    //MPNET : 3827 ms
                    //MFP   : ---
                    //CALEN : 41 ms
                    //NCALC : ---
                    lines = MakeTenK("2-(3*5)^2+7/(2-8)*2");
                    break;
            }

            Console.WriteLine("Starting benchmarks ...");
            Console.WriteLine("----------");

            // The implementation here... YAMP
            Benchmark("YAMP", lines, query => yamp.Evaluate(query));

            //http://www.codeproject.com/Articles/53001/LL-Mathematical-Parser
            Benchmark("LLMathParser", lines, query => llmp.Evaluate(query, new char[0], new double[0]));

            //http://www.codeproject.com/Articles/11164/Math-Parser
            Benchmark("MathParser", lines, query => mpparser.Evaluate(query));

            //http://www.codeproject.com/Tips/381509/Math-Parser-NET-Csharp
            Benchmark("MathParserTK", lines, query => mptk.Parse(query, false));

            //http://www.codeproject.com/Articles/274093/Math-Parser-NET
            Benchmark("MathParserNet", lines, query => mpnet.Simplify(query));

            //http://www.codeproject.com/Articles/23061/MathParser-Math-Formula-Parser
            Benchmark("MathFormulaParser", lines, query => mfmp.Calculate(query));

            //http://www.codeproject.com/Articles/246374/A-Calculation-Engine-for-NET
            Benchmark("CalcEngine", lines, query => calcEngine.Evaluate(query));

            //http://ncalc.codeplex.com/
            //Benchmark("NCalc", lines, query => new NCalc.Expression(query, NCalc.EvaluateOptions.NoCache).Evaluate());
        }