. Net 4.0 Parallel Library practicality Walkthrough

Source: Internet
Author: User
Keywords Walkthrough practicality array or myself
Tags .mall added array it is learn net no new reading

Since VS2010 released nearly half a year, although all day want to learn new things, to update themselves, found that the original oneself is basically also very lazy, 2008 not how long it is useless, helpless by 2010. In a few days, the IDE looks like 05, 08 almost, added small features, later slowly experience it, the first feeling of slow start. The main or. Net 4.0 changes, in fact, is tinkering, language features almost no new features, C # More dynamic, a decade ago, VB support late binding. Instead of focusing on the framework, the new parallel support should be the biggest change.

VS2010 conference I have also been to, parallel support is a big selling point. At that time, I remember a mm on the stage adds a asparallel () to a LINQ query statement, and the performance is magically raised by one, and applause is made. It's really fun to improve the performance of the program. In the reading of electronic periodicals, see cold students, and Wu Qin of the article, give me these rookie to shock the inspiration, originally I have fallen far behind in reading college students.

Then start to learn, take parallel axe. First grab a cushion back:

static void Set (int length) {var array = new Int[length, length, length]; for (int i = 0; i < length; i++) for (int j = 0; ; Length; J + + for (int k = 0; k < length; k++) Array[i, j, K] = System.Threading.Thread.CurrentThread.ManagedThreadId; }

And then ask the true God:

static void Parallelset (int length) {var array = new Int[length, length, length]; Parallel.For (0, length, I => {for (int j = 0; J < length; J +) for (int k = 0; k < length; k++) Array[i, j, K] = system.th Reading. Thread.CurrentThread.ManagedThreadId; }); }

PK:

Codetimer.time ("Single Thread", () => Set (100)); Codetimer.time ("ListBox Thread", () => parallelset (100));

As a result, 1136ms:729ms, really good. But the MSDN example might have been harmonized, so I always change the test process. Sure enough to find another.

Continue >> Next [1th] [page 2nd] [3rd]
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.