对于 Array,使用 map() & 是否更有效?在javascript中减少()而不是forEach

For Array, is it more efficient to use map() amp; reduce() instead of forEach() in javascript?(对于 Array,使用 map() amp; 是否更有效?在javascript中减少()而不是forEach()?)
本文介绍了对于 Array,使用 map() & 是否更有效?在javascript中减少()而不是forEach()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

1)我们知道,map() 和reduce() 没有副作用.如今,我们在手机上也有多核.那么使用它们是否更有效?

1)As we know, there's no side-effect with map() and reduce(). Nowadays, we also have muti-core on cell phone. So is it more efficient to use them?

2)另一方面,在大多数浏览器上只有一个 js 线程可以执行.所以map()和reduce()是为服务端脚本准备的?

2)On the other hand, there's only 1 thread for js to execute on most of the browsers. Therefor map() and reduce() are prepared for server-side scripting?

推荐答案

这很容易被忽视,但获得 MapReduce 好处的关键在于

It is easily overlooked, but the key to getting the benefits of MapReduce is to

A) 利用优化的随机播放.通常,您的 map 和 reduce 函数可以用慢速语言实现,只要 shuffle(最昂贵的操作)得到很好的优化,它仍然是快速且可扩展的.

A) Exploit the optimized shuffle. Often, your map and reduce functions can be implemented in a slow language, as long as the shuffle - the most expensive operation - is well optimized, it will still be fast and scalable.

B) 利用检查点功能从节点故障中恢复(但希望您的 CPU 内核不会出现故障).

B) Exploit the checkpointing functionality to recover from node failures (but hopefully, your CPU cores won't fail).

所以说到底,map-reduce 实际上既不是 map,也不是 reduce 函数.这是关于它周围的框架;即使使用糟糕的map"和reduce"功能,它也会为您提供良好的性能(除非您在 shuffle 步骤中失去对数据集大小的控制!).

So in the end, map-reduce is actually neither about the map, nor the reduce functions. It's about the framework around it; which will give you good performance even with bad "map" and "reduce" functions (unless you lose control over your data set size in the shuffle step!).

在单个节点上执行多线程 map-reduce 所获得的收益相当低,并且很可能有 比 map-reduce 更好的方法来为共享内存架构并行化您的商店...

The gains to be obtained from doing a multi-threaded map-reduce on a single node are fairly low, and most likely there are much better ways of parallelizing your shop for shared memory architectures than map-reduce...

不幸的是,现在围绕 mapreduce 有很多炒作(而且理解太少).如果您查找 原始论文,它会详细介绍备份任务"、机器故障"和局部优化"(对于内存中的单主机用例,这两者都没有意义).

Unfortunately, there is a lot of hype (and too little understanding) surrounding mapreduce these days. If you look up the original paper, it goes into detail about "Backup Tasks", "Machine Failures" and "locality optimization" (neither of which makes sense for an in-memory single-host use case).

仅仅因为它有一个map"和一个reduce"并不能使它成为一个mapreduce".
如果它具有优化的随机播放、节点崩溃和落后者恢复,则它只是一个 MapReduce.

Just because it has a "map" and a "reduce" doesn't make it a "mapreduce" yet.
It's only a MapReduce if it has an optimized shuffle, node crash and straggler recovery.

这篇关于对于 Array,使用 map() & 是否更有效?在javascript中减少()而不是forEach()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How do I can get a text of all the cells of the table using testcafe(如何使用 testcafe 获取表格中所有单元格的文本)
node_modules is not recognized as an internal or external command(node_modules 未被识别为内部或外部命令)
How can I create conditional test cases using Protractor?(如何使用 Protractor 创建条件测试用例?)
PhantomJS and clicking a form button(PhantomJS 并单击表单按钮)
Clicking #39;OK#39; on alert or confirm dialog through jquery/javascript?(在警报上单击“确定或通过 jquery/javascript 确认对话框?)
QunitJS-Tests don#39;t start: PhantomJS timed out, possibly due to a missing QUnit start() call(QunitJS-Tests 不启动:PhantomJS 超时,可能是由于缺少 QUnit start() 调用)