. Net 4.0 Parallel library practice (preface)

Source: Internet
Author: User

Since the release of vs2010 for nearly half a year, although I want to learn new things all day, I found myself very lazy when I was about to update myself. It didn't take long for 2008, but I had to be 2010. After a few days, the IDE looks like 05 and 08. With some small features added, you can try it later. First, you feel that the startup speed is much slower. The main change lies in. Net 4.0. In fact, it refers to the revision and supplement, and the language features have almost no new features. C # has a dynamic and VB supports later binding 10 years ago. I had to pay attention to the Framework. The new parallel support should be the biggest change.

I have also visited the vs2010 press conference. Parallel support is a major selling point. At that time, I remember that one mm on the platform added asparallel () to a LINQ query statement, and the performance was magically doubled. It is indeed very easy to improve program performance, is the most interesting. When reading electronic journals, I saw an article by Leng and Wu Qin, which inspired me by these cainiao. I used to fall far behind college students.

Let's get started and start with parallel. First grab a pad back:

Staticvoid set (INT length)
{
VaR array = newint [length, length, length];
For (INT I = 0; I <length; I ++)
For (Int J = 0; j <length; j ++)
For (int K = 0; k <length; k ++)
Array [I, j, k] = system. Threading. thread. currentthread. managedthreadid;
}

Then let us know:

Staticvoid parallelset (INT length)
{
VaR array = newint [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. Threading. thread. currentthread. managedthreadid;
});
}

PK:

Codetimer. Time ("single thread", 100, () => set (100 ));
Codetimer. Time ("multiple thread", 100, () => parallelset (100 ));

 

The result is 1136 Ms: 729 MS, which is really good. However, the msdn example may have been harmonized, so it will always change the test process. We found another one.

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.