Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Diagnostics;
- class Program
- {
- static int[] N = {10, 100, 1000, 100000};
- static int[] M = {2, 3, 4, 5, 10};
- const double c = 114.105;
- const int posled_start = 10;
- const int potok_start = 100;
- static void Main() {
- foreach(var n in N){
- Stopwatch time = new Stopwatch();
- time.Start();
- for(int j = 0; j<posled_start;j++){
- double[] mass_posl = new double[n];
- for(int i = 0; i<n; i++){
- mass_posl[i] = i*c;
- }
- }
- time.Stop();
- Console.WriteLine("Total time последовательной обработки при N = {0}: {1} ms.", n, time.Elapsed.TotalMilliseconds/posled_start);
- }
- foreach(var n in N){
- foreach(var m in M){
- Stopwatch time = new Stopwatch();
- time.Start();
- for(int j = 0; j<potok_start;j++){
- Thread[] threads = new Thread[m];
- double[] mass = new double[n];
- for (int i = 0; i < m; i++)
- {
- Param param = new Param(n, m, i, mass);
- threads[i] = new Thread(param.Work);
- threads[i].Start();
- }
- for (int i = 0; i < m; i++)
- threads[i].Join();
- }
- time.Stop();
- Console.WriteLine("Total time паралельной обработки при N = {0} и M = {1}: {2} ms.", n, m, time.Elapsed.TotalMilliseconds/potok_start);
- }
- }
- }
- }
- public class Param{
- const double c = 5.7;
- private int n;
- private int m;
- private int o;
- private double[] mass;
- public Param(int _n, int _m, int _o, double[] _mass){
- this.n = _n;
- this.m = _m;
- this.o = _o;
- this.mass = _mass;
- }
- public void Work()
- {
- int ThreadNumber = (int)o;
- int part = n / m;
- for (int i = ThreadNumber * part; i < (ThreadNumber + 1) * part; i++)
- {
- mass[i] = i*c;
- }
- }
- }
Add Comment
Please, Sign In to add comment