CPU与内存使用量(理论) [英] CPU vs Memory usage (theory)

查看:186
本文介绍了CPU与内存使用量(理论)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Stack Overflow上发现了一些关于内存使用和CPU使用的有趣帖子,但是他们都没有直接解决这个看似简单的问题:

I found some interesting post about memory usage and CPU usage here on Stack Overflow, however none of them had a direct approach to the apparently simple question:


作为JavaScript应用程序中的通用策略,使用内存(存储数据)或CPU(每次重新计算数据)的性能方面是否更好?

As a generic strategy in a JavaScript app, is it better in terms of performances to use memory (storing data) or CPU (recalculating data each time)?

我指的是常见浏览器环境中的javascript使用情况(FF,Chrome,IE> 8)

I refer to javascript usage in common browsers environment (FF, Chrome, IE>8)

是否有人更直接记录在案的答案?

Does anybody have a more direct and documented answer to this?

---编辑---

好的,我理解这个问题非常通用。我试着减少范围。

Ok, I understand the question is very generic. I try to reduce the "scope".

阅读你的答案我意识到真正的问题是:如何解读我的javascript代码仍然有好处的内存限制演出?。
环境:常见浏览器环境(FF,Chrome,IE> 8)

Reading your answer I realized that the real question is: "how to undestand the memory limit under which my javascript code still has good performances?". Environment: common browsers environment (FF, Chrome, IE>8)

我使用的函数不是非常复杂的数学函数,但可以产生相当大的数量数据(300-400kb),我想了解每次重新计算它们是否更好或只是将结果存储在变量中。

Functions I use are not very complex math functions, but can produce quite a huge amount of data (300-400kb) and I wanted to understand if it was better to recalculate them every time or just store results in variables.

推荐答案

模糊相关 - 当你开始使用大型对象/数组时,浏览器中的JS会非常耗费内存。如果您考虑由canvas元素或其他富媒体API生成的二进制数据,那么显然您不希望以传统方式存储这些数据 - 忽略性能问题,这也很重要。

Vaguely related - JS in browsers is extremely memory hungry when you start using large objects / arrays. If you think about binary data produced by canvas elements, or other rich media APIs, then clearly you do not want to be storing this data in traditional ways - disregarding performance issues, which are also important.

来自 MDN文章谈论JS Typed Arrays


随着Web应用程序变得越来越强大,添加音频和视频操作,使用WebSockets访问原始数据等功能,它已经变得清晰有时JavaScript代码能够快速轻松地操作原始二进制数据。

As web applications become more and more powerful, adding features such as audio and video manipulation, access to raw data using WebSockets, and so forth, it has become clear that there are times when it would be helpful for JavaScript code to be able to quickly and easily manipulate raw binary data.

这是一个 JS Perf比较数组,另一个特别关注画布 ,所以你可以得到一些关于它们如何工作的直接例子。希望这很有用。

Here's a JS Perf comparison of arrays, and another looking at canvas in particular, so you can get some direct examples on how they work. Hope this is useful.

这篇关于CPU与内存使用量(理论)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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