当将并行提高性能 [英] When will parallel increase performance

查看:156
本文介绍了当将并行提高性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,当并行的使用将提高性能。
人> ,改变了每个人的名字的String.Empty我用一个简单的code,它跑了超过10万项名单中测试它

I'm trying to understand when the usage of parallel will increase the performance.
I tested it with a simple code that ran over 100,000 items in List<Person> and changed the name of each one to string.Empty.

并行版本的时候了两次,然后普通版。 (是的,我有更多的单核测试...)

The parallel version took twice the time then the regular version. (Yes I tested with more the one core...)

我看到回答说数据的切片并不总是并行的良好性能。
另外这款谨慎重复在 MSDN 教程

I saw this answer saying a slice of data that not always the parallel is good for performance.
Also this caution repeated in each page of the parallel examples in the MSDN tutorial:

这些实施例主要是用来证明使用,和可以是或   可能无法运行比同等顺序LINQ到对象更快   查询

These examples are primarily intended to demonstrate usage, and may or may not run faster than the equivalent sequential LINQ to Objects queries

我需要一些规则和技巧时,并行会增加我的code中的表现时不会。
答案显然是测试你的code,若并行循环更快使用它,是绝对正确的,但我想每个他写道循环中没有一个运行性能分析。

I need some rules and tips when parallel will increase the performance of my code and when will not.
The obvious answer is "Test your code, if the parallel loop is faster use it", is absolutely right, but I guess no one run performance analysis on each loop he writes.

推荐答案

想想当它是值得的并行化的东西在现实生活中。当是它更好地坐下来,做了自己的工作从开始到结束,而当它更好雇用20人?

Think about when it is worthwhile to parallelize something in real life. When is it better to just sit down and do a job yourself from start to finish, and when is it better to hire twenty guys?

  • 是工作本身并行或串行本质?有些工作不是并行可言:九女不能一起工作使一个婴儿一个月。有些工作是并行的,但给糟糕的结果:你可以雇用20人,并指定每个人五十页战争与和平读了你,然后让他们每个人写一篇文章的二十分之一,胶水所有的作文片段在一起,提交的文件;这是不太可能导致一个好成绩。有些工作是非常并行:20人用铲子可以挖一个洞,比一个人更快

  • Is the work inherently parallelizable or inherently serial? Some jobs are not parallelizable at all: nine women can't work together to make one baby in a month. Some jobs are parallelizable but give lousy results: you could hire twenty guys and assign each of them fifty pages of War and Peace to read for you, and then have each of them write one twentieth of an essay, glue all the essay fragments together and submit the paper; that's unlikely to result in a good grade. Some jobs are very parallelizable: twenty guys with shovels can dig a hole much faster than one guy.

如果工作本质上是并行的,不并行化实际上节省时间?你可以煮意大利面的锅具百面条吧,或者你可以煮二盆面条的五面在每个和结束时倒的结果一起。我向你保证,并行烹调意大利面的任务不会导致让你的晚餐得更快。

If the work is inherently parallelizable, does parallelization actually save time? You can cook a pot of spaghetti with a hundred noodles in it, or you can cook twenty pots of spaghetti with five noodles in each and pour the results together at the end. I guarantee you that parallelizing the task of cooking spaghetti does not result in getting your dinner any faster.

如果工作本质上是并行的,并且有可能节省时间,并聘请那些家伙的费用及时支付存款?如果它的速度更快,只是自己做的工作比它雇用的家伙,并行化是不是一个双赢。雇用20人做一份工作,有五个你秒钟,希望他们会得到它在一季度末二做的并不是储蓄,如果它需要你每天找人。

If the work is inherently parallelizable, and there is a possible time savings, does the cost of hiring those guys pay for the savings in time? If it's faster to just do the job yourself than it is to hire the guys, parallelization is not a win. Hiring twenty guys to do a job that takes you five seconds, and hoping that they'll get it done in a quarter second is not a savings if it takes you a day to find the guys.

并行化往往是一个双赢当工作的巨大并行的。设置十万指向空的东西一台电脑可以在第二个一小部分做的;没有巨大的成本,所以没有积蓄。试着做一些不平凡的;说,写一个编译器和做的方法体的语义分析并行。你会更容易拿到一场胜利那里。

Parallelization tends to be a win when the work is enormous and parallelizable. Setting a hundred thousand pointers to null is something a computer can do in a tiny fraction of a second; there's no enormous cost, so there's no savings. Try doing something non-trivial; say, write a compiler and do semantic analysis of method bodies in parallel. You'll be more likely to get a win there.

这篇关于当将并行提高性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆