Оценить время работы метода - C#

Узнай цену своей работы

Формулировка задачи:

Необходимо оценить время работы метода. Но он почему-то не хочет этого делать.Как я поняла, он не может конвертировать. Подскажите как правильно это сделать. Заранее благодарю за помощь. это библиотека
Листинг программы
  1. namespace ClassLibrary2
  2. {
  3. public class TimeValue
  4. {
  5. public delegate double DToD(double arg1);
  6. public static double EvalTimeDtoD(int count, DToD fun, double x1,double x2,double dx)
  7. {
  8. DateTime start, finish;
  9. double res = 0;
  10. start = DateTime.Now;
  11. for (int i = 1; i <= count;i++)
  12. {
  13. do
  14. {
  15. fun(x1);
  16. x1 += dx;
  17. } while (x1 <= x2);
  18. }
  19. finish = DateTime.Now;
  20. res = (finish - start).Milliseconds;
  21. return res;
  22. }
  23. }
  24. public class Class1
  25. {
  26. public static double Kol(double X,double EPS)
  27. {
  28. double a = X;
  29. double res = 0;
  30. int k = 0;
  31. do
  32. {
  33. res += a;
  34. a *= (-(Math.Pow(X, 2))) * (2 * k + 1);
  35. a /= (2 * k + 3);
  36. k++;
  37. Console.WriteLine(a);
  38. res += a;
  39. } while (Math.Abs(a) >= EPS);
  40. return k;
  41. }
  42. public static double MyAtan(double X, double EPS)
  43. {
  44. double a = X;
  45. double res = 0;
  46. int k = 0;
  47. do
  48. {
  49. res += a;
  50. a *= (-(Math.Pow(X, 2))) * (2*k+1);
  51. a /= (2*k+3);
  52. k++;
  53. Console.WriteLine(a);
  54. res += a;
  55. } while (Math.Abs(a) >= EPS);
  56. return res;
  57. }
  58. }
  59. }
WindowsForm
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace WindowsFormsApplication1
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. Result.ColumnCount = 5;
  18. Result.Columns[0].HeaderText = "X";
  19. Result.Columns[1].HeaderText = "Math.Atan";
  20. Result.Columns[2].HeaderText = "MyAtan";
  21. Result.Columns[3].HeaderText = "Разница";
  22. Result.Columns[4].HeaderText = "Сумма";
  23.  
  24. }
  25. private void EPSLabel_Click(object sender, EventArgs e)
  26. {
  27. }
  28. private void AtanButton_Click(object sender, EventArgs e)
  29. {
  30. int count = 1;
  31. double x1 = Convert.ToDouble(X1TextBox.Text);
  32. double x2 = Convert.ToDouble(X2TextBox.Text);
  33. double dx = Convert.ToDouble(dXTextBox.Text);
  34. double eps = Convert.ToDouble(EpsTextBox.Text);
  35. int MyRow = Convert.ToInt32(x2 / dx);
  36. count = Convert.ToInt32(ReturnTextBox.Text);
  37. TimeTextBox1.Text = (ClassLibrary2.TimeValue.EvalTimeDtoD(count, Math.Atan, x1, x2, dx)).ToString();
  38.  
  39. TimeTextBox2.Text = (ClassLibrary2.TimeValue.EvalTimeDtoD(count, ClassLibrary2.Class1.MyAtan, x1, x2, dx)).ToString();// Тут выдает 2 ошибки:
  40.  
  41. 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
  42. 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]
  43. \
  44.  
  45. Result.RowCount = MyRow;
  46. int n = 0;
  47. do
  48. {
  49. Result[0, n].Value = x1;
  50. Result[1, n].Value = Math.Atan(x1);
  51. Result[2, n].Value = ClassLibrary2.Class1.MyAtan(x1,eps);
  52. Result[3, n].Value = (double)Result[1, n].Value - (double)Result[2, n].Value;
  53. Result[4, n].Value = ClassLibrary2.Class1.Kol(x1, eps);
  54. n++;
  55. x1 += dx;
  56. } while (x1 <= x2);
  57. }
  58. }
  59. }

Решение задачи: «Оценить время работы метода»

textual
Листинг программы
  1. TimeTextBox1.Text = (ClassLibrary2.TimeValue.EvalTimeDtoD(count, new ClassLibrary2.TimeValue.DToD(Math.Atan), x1, x2, dx)).ToString();

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

10   голосов , оценка 4 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут