Exemple #1
0
        void Benchmark_Click(Object _sender, EventArgs _e1)
        {
            try
            {
                // For optimum performance evaluate in a batch...

                // Redefine vector variables to contain multiple values
                MTParser benchParser = new MTParser();
                benchParser.copy(m_parser);

                MTDoubleVector x = new MTDoubleVector();
                MTDoubleVector y = new MTDoubleVector();
                MTDoubleVector z = new MTDoubleVector();
                x.create("x");
                y.create("y");
                z.create("z");

                benchParser.undefineAllVars();
                benchParser.defineVar(x as IMTVariable);
                benchParser.defineVar(y as IMTVariable);
                benchParser.defineVar(z as IMTVariable);

                // Compile the expression only once
                benchParser.compile(Expr.Text);

                // Generate random variable values...
                int nbEvals = 400000;

                double[]      xval = new double[nbEvals];
                double[]      yval = new double[nbEvals];
                double[]      zval = new double[nbEvals];
                System.Random r    = new System.Random(100);

                for (int i = 0; i < nbEvals; i += 1)
                {
                    xval[i] = r.Next(0, 1000);
                    yval[i] = r.Next(0, 1000);
                    zval[i] = r.Next(0, 1000);
                }

                // Set values...
                x.setValueVector(xval);
                y.setValueVector(yval);
                z.setValueVector(zval);


                double[] results = new double[nbEvals];                         // this will contain all the results after evaluations

                long beginTime = 0;
                long endTime   = 0;
                beginTime = GetTickCount();                                             // start the timer
                benchParser.evaluateCompiledBatch(nbEvals, results);                    // do all evaluations in one call, avoiding multiple COM calls
                endTime = GetTickCount();                                               // stop the timer

                long elapsedTime = 0;
                elapsedTime = endTime - beginTime;

                long   nbEvalSec   = 0;
                double timePerEval = 0;
                timePerEval = elapsedTime / (double)nbEvals;
                nbEvalSec   = (long)(nbEvals / elapsedTime * 1000.0);

                Msg.Text = "Nb. Evaluations: " + nbEvals;
                Msg.Text = Msg.Text + Environment.NewLine;
                Msg.Text = Msg.Text + "Elapsed time (ms): " + elapsedTime;
                Msg.Text = Msg.Text + Environment.NewLine;
                Msg.Text = Msg.Text + "Time per evaluation (ms): " + timePerEval;
                Msg.Text = Msg.Text + Environment.NewLine;
                Msg.Text = Msg.Text + "Nb. Eval per sec: " + nbEvalSec;
            }
            catch (Exception e)
            {
                Msg.Text = "Error: " + e.Message;
            }
        }
		void Benchmark_Click(Object _sender, EventArgs _e1) 
		{		
			
			try
			{
				// For optimum performance evaluate in a batch...

				// Redefine vector variables to contain multiple values 
				MTParser benchParser = new MTParser();
				benchParser.copy( m_parser );
				
				MTDoubleVector x = new MTDoubleVector();
				MTDoubleVector y = new MTDoubleVector();
				MTDoubleVector z = new MTDoubleVector();
				x.create("x");
				y.create("y");
				z.create("z");
                
				benchParser.undefineAllVars();
				benchParser.defineVar(x as IMTVariable);
				benchParser.defineVar(y as IMTVariable);
				benchParser.defineVar(z as IMTVariable);			

				// Compile the expression only once
				benchParser.compile(Expr.Text);				
				
				// Generate random variable values...
				int nbEvals = 400000;				

				double[] xval = new double[nbEvals];
				double[] yval = new double[nbEvals];
				double[] zval = new double[nbEvals];
				System.Random r = new System.Random(100);

				for(int i = 0; i < nbEvals; i += 1)
				{					
					xval[i] = r.Next(0, 1000);
					yval[i] = r.Next(0, 1000);
					zval[i] = r.Next(0, 1000);
				}
				
				// Set values...				
				x.setValueVector(xval);
				y.setValueVector(yval);
				z.setValueVector(zval);				
				
				
				double[] results = new double[nbEvals];		// this will contain all the results after evaluations
				
				long beginTime = 0;
				long endTime = 0;				
				beginTime = GetTickCount();								// start the timer
				benchParser.evaluateCompiledBatch(nbEvals, results);	// do all evaluations in one call, avoiding multiple COM calls							
				endTime = GetTickCount();								// stop the timer

				long elapsedTime = 0;
				elapsedTime = endTime - beginTime;				

				long nbEvalSec = 0;
				double timePerEval = 0;
				timePerEval = elapsedTime / (double)nbEvals;
				nbEvalSec = (long)(nbEvals / elapsedTime * 1000.0);

				Msg.Text = "Nb. Evaluations: " + nbEvals;
				Msg.Text = Msg.Text + Environment.NewLine ;
				Msg.Text = Msg.Text + "Elapsed time (ms): " + elapsedTime;
				Msg.Text = Msg.Text + Environment.NewLine ;
				Msg.Text = Msg.Text + "Time per evaluation (ms): " + timePerEval;
				Msg.Text = Msg.Text + Environment.NewLine ;
				Msg.Text = Msg.Text + "Nb. Eval per sec: " + nbEvalSec;
			}
			catch ( Exception e)
			{
				Msg.Text = "Error: " + e.Message;
			}
		}