Advertisement
Guest User

Untitled

a guest
Sep 10th, 2010
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.Windows.Forms;
  4.  
  5. namespace ClickTest
  6. {
  7. public partial class Form1 : Form
  8. {
  9. public Form1()
  10. {
  11. InitializeComponent();
  12. ClickTest();
  13. MouseClickTest();
  14. ClickTest();
  15. MouseClickTest();
  16. }
  17.  
  18. private void ClickTest()
  19. {
  20. Button[] buttons = CreateButtons(1000);
  21. Stopwatch timer = new Stopwatch();
  22. timer.Start();
  23. for (int i = 0; i < 1000; i++) buttons[i].Click += Form1_Click;
  24. timer.Stop();
  25. Console.WriteLine("Click: " + timer.ElapsedMilliseconds);
  26. }
  27.  
  28. private void MouseClickTest()
  29. {
  30. Button[] buttons = CreateButtons(1000);
  31. Stopwatch timer = new Stopwatch();
  32. timer.Start();
  33. for (int i = 0; i < 1000; i++) buttons[i].MouseClick += Form1_MouseClick;
  34. timer.Stop();
  35. Console.WriteLine("MouseClick: " + timer.ElapsedMilliseconds);
  36. }
  37.  
  38. private Button[] CreateButtons(int length)
  39. {
  40. Button[] buttons = new Button[length];
  41. for (int i = 0; i < length; i++) buttons[i] = new Button();
  42. return buttons;
  43. }
  44.  
  45. private void Form1_Click(object sender, EventArgs e)
  46. {
  47. throw new NotImplementedException();
  48. }
  49.  
  50. private void Form1_MouseClick(object sender, MouseEventArgs e)
  51. {
  52. throw new NotImplementedException();
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement