Оценить время работы метода - C#
Формулировка задачи:
Необходимо оценить время работы метода. Но он почему-то не хочет этого делать.Как я поняла, он не может конвертировать. Подскажите как правильно это сделать. Заранее благодарю за помощь.
это библиотека
WindowsForm
namespace ClassLibrary2
{
public class TimeValue
{
public delegate double DToD(double arg1);
public static double EvalTimeDtoD(int count, DToD fun, double x1,double x2,double dx)
{
DateTime start, finish;
double res = 0;
start = DateTime.Now;
for (int i = 1; i <= count;i++)
{
do
{
fun(x1);
x1 += dx;
} while (x1 <= x2);
}
finish = DateTime.Now;
res = (finish - start).Milliseconds;
return res;
}
}
public class Class1
{
public static double Kol(double X,double EPS)
{
double a = X;
double res = 0;
int k = 0;
do
{
res += a;
a *= (-(Math.Pow(X, 2))) * (2 * k + 1);
a /= (2 * k + 3);
k++;
Console.WriteLine(a);
res += a;
} while (Math.Abs(a) >= EPS);
return k;
}
public static double MyAtan(double X, double EPS)
{
double a = X;
double res = 0;
int k = 0;
do
{
res += a;
a *= (-(Math.Pow(X, 2))) * (2*k+1);
a /= (2*k+3);
k++;
Console.WriteLine(a);
res += a;
} while (Math.Abs(a) >= EPS);
return res;
}
}
}using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Result.ColumnCount = 5;
Result.Columns[0].HeaderText = "X";
Result.Columns[1].HeaderText = "Math.Atan";
Result.Columns[2].HeaderText = "MyAtan";
Result.Columns[3].HeaderText = "Разница";
Result.Columns[4].HeaderText = "Сумма";
}
private void EPSLabel_Click(object sender, EventArgs e)
{
}
private void AtanButton_Click(object sender, EventArgs e)
{
int count = 1;
double x1 = Convert.ToDouble(X1TextBox.Text);
double x2 = Convert.ToDouble(X2TextBox.Text);
double dx = Convert.ToDouble(dXTextBox.Text);
double eps = Convert.ToDouble(EpsTextBox.Text);
int MyRow = Convert.ToInt32(x2 / dx);
count = Convert.ToInt32(ReturnTextBox.Text);
TimeTextBox1.Text = (ClassLibrary2.TimeValue.EvalTimeDtoD(count, Math.Atan, x1, x2, dx)).ToString();
TimeTextBox2.Text = (ClassLibrary2.TimeValue.EvalTimeDtoD(count, ClassLibrary2.Class1.MyAtan, x1, x2, dx)).ToString();// Тут выдает 2 ошибки:
Error 2 Argument 2: cannot convert from 'method group' to 'ClassLibrary2.TimeValue.DToD' C:\Users\1\Documents\Visual Studio 2013\Projects\lab C#\ClassLibrary2\WindowsFormsApplication1\Form1.cs 44 78 WindowsFormsApplication1
Error 1 The best overloaded method match for 'ClassLibrary2.TimeValue.EvalTimeDtoD(int, ClassLibrary2.TimeValue.DToD, double, double, double)' has some invalid arguments C:\Users\1\Documents\Visual Studio 2013\Projects\lab C#\ClassLibrary2\WindowsFormsApplication1\Form1.cs 44 34 WindowsFormsApplication1]
\
Result.RowCount = MyRow;
int n = 0;
do
{
Result[0, n].Value = x1;
Result[1, n].Value = Math.Atan(x1);
Result[2, n].Value = ClassLibrary2.Class1.MyAtan(x1,eps);
Result[3, n].Value = (double)Result[1, n].Value - (double)Result[2, n].Value;
Result[4, n].Value = ClassLibrary2.Class1.Kol(x1, eps);
n++;
x1 += dx;
} while (x1 <= x2);
}
}
}Решение задачи: «Оценить время работы метода»
textual
Листинг программы
TimeTextBox1.Text = (ClassLibrary2.TimeValue.EvalTimeDtoD(count, new ClassLibrary2.TimeValue.DToD(Math.Atan), x1, x2, dx)).ToString();