Facebook
From Unique Cassowary, 7 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 349
  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.Threading;
  10. using System.Diagnostics;
  11.  
  12. namespace zd1.1
  13. {
  14.     class Program
  15.     {
  16.  
  17.         public static int czas_tworzenia, caly_czas_tworzenia, czas_zwolnienia, caly_czas_zwolnienia = 0;
  18.         static void losowanie()
  19.         {
  20.             Random rand = new Random();
  21.             int x = rand.Next(1, 10);
  22.         }
  23.  
  24.  
  25.         static void Main(string[] args)
  26.         {
  27.             Stopwatch tworzenie = new Stopwatch();
  28.             Stopwatch zwolnienie = new Stopwatch();
  29.  
  30.  
  31.             for (int i = 0; i < 10; i++)
  32.             {
  33.                 Thread watek1 = new Thread(losowanie);
  34.  
  35.                 tworzenie.Start();
  36.                 watek1.Start();
  37.                 tworzenie.Stop();
  38.  
  39.                 zwolnienie.Start();
  40.                 watek1.Join();
  41.                 zwolnienie.Stop();
  42.  
  43.  
  44.                 caly_czas_tworzenia = caly_czas_tworzenia + Convert.ToInt32(tworzenie.ElapsedMilliseconds);
  45.                 caly_czas_zwolnienia = caly_czas_zwolnienia + Convert.ToInt32(zwolnienie.ElapsedMilliseconds);
  46.  
  47.                 Console.WriteLine("Czas tworzenia " + i + " watku: " + Convert.ToInt32(tworzenie.ElapsedMilliseconds));
  48.  
  49.  
  50.             }
  51.             Console.WriteLine("Czas tworzenia wszystkich watkow: " + caly_czas_tworzenia);
  52.             Console.WriteLine("Czas zwolnienia wszystkich watkow: " + caly_czas_zwolnienia);
  53.  
  54.  
  55.  
  56.             Console.ReadLine();
  57.  
  58.  
  59.         }
  60.     }
  61.  
  62. }