.


:




:

































 

 

 

 


Using System.Threading.Tasks;. class DemoParallelFor { static int[] data;




class DemoParallelFor { static int[] data;

// , .

// , static void MyTrlansform (int i) { data[i] = data[i] / 10;

if(data[i] < 10000) data[i] = 0;

if(data[i] > 10000 & data[i] < 20000) data[i] = 100; if(data[i] > 20000 & data[i] < 30000) data[i] = 200; if(data[i] > 30000) data[i] = 300;

}

static void Main() {

Console.WriteLine(" .");

data = new int[100000000];

// for. for (int i=0; i < data.Length; i++) data[i] = i;

// For().

Parallel.For(0, data.Length, MyTransform);

Console.WriteLine(" .");

}

}

. , , for data. , For (), data . , . For () MyTransform () , . , , For () .

, , , , . , , , , , . for For () . , , , , , , .

for, .

// // for.

Using System;

Using System.Threading.Tasks; using System.Diagnostics;

class DemoParallelFor { static int[] data;

// , .

// , static void MyTransform(int i) { data[i] = data[i] / 10;

if(data[i] < 1000) data[i] = 0;

if(data[i] > 1000 & data[i] < 2000) data[i] = 100; if(data[i] > 2000 & data[i] < 3000) data[i] = 200; if(data[i] > 3000) data[i] = 300;

}

static void Main() {

Console.WriteLine(" .");

// Create Stopwatch // .

Stopwatch sw = new Stopwatch ();

data = new int[100000000];

// , sw.Start ()';

// .

Parallel.For(0, data.Length, (i) => data[i] = i);

Sw.Stop ();

Console.WriteLine(" : " +

"{0} ", sw.Elapsed.TotalSeconds);

Sw.Reset (); sw.Start ();

// , for(int i=0; i < data.Length; i++) data[i] = i;

Sw.Stop ();

Console.WriteLine(" : " +

"{0} ", sw.Elapsed.TotalSeconds);

// , sw.Start();

// .

Parallel.For(0, data.Length, MyTransform);

Sw.Stop();

Console.WriteLine(" : " +

"{0} ", sw.Elapsed.TotalSeconds);

Sw.Reset (); sw.Start();

// , for(int i=0; i < data.Length; i++) MyTransform(i);

Sw.Stop ();

Console.WriteLine(" : " +

"{0} ", sw.Elapsed.TotalSeconds);

Console.WriteLine(" .");

}

}





:


: 2016-12-03; !; : 370 |


:

:

- , , .
==> ...

1524 - | 1338 -


© 2015-2024 lektsii.org - -

: 0.01 .