写“力量”高效的代码

发布于 2024-09-26 16:42:20 字数 378 浏览 1 评论 0原文

可能的重复:
节能软件编码

Adob​​e 在 Google I/O 大会上宣布即将推出下一版 Flash 10.1对于功耗很重要的设备来说,提高效率。

这让我开始思考:如何编写消耗更少电量的代码?有关于这个主题的任何有用的资源吗?

我的猜测是,它是以下各项的组合:

  • 降低应用程序的复杂性
  • ,编写快速执行的高效代码(大概是因为处理时间 = 功耗)

Possible Duplicate:
Power Efficient Software Coding

Adobe announced at Google I/O that it's next version of Flash 10.1 is going to more efficient for devices where power consumption matters.

This got me to thinking: how do you write code that uses less power? Are there any helpful resources regarding this topic?

My guess would be that it is a combination of:

  • reducing the complexity of your application
  • writing efficient code that is executed quickly (presumably because processing time = power consumed)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

夜灵血窟げ 2024-10-03 16:42:20

实际上还有一种更大的降低功耗的方法尚未触及。

让我们以一台计算机为例,将所有功能分为两个基本组。那些以硬件实现的和那些以软件实现的。

如果一个功能是在硬件中实现的(也就是说,有一个电路,您可以将输入放在一组电线上,输出从另一组电线上出来),那么功耗等于总数中消耗的功率的门。时钟滴答一声(消耗一点电力),总线输出变热(消耗一点电力)。

如果一个功能是在软件中实现的(也就是说,没有用于实现该功能的单个电路),那么它需要使用多个电路、多个时钟周期,并且通常需要大量的内存调用。请记住,SRAM(用于处理器寄存器)由 D 触发器组成,只要它们在使用中,它们就会不断消耗电量。

作为一个简单的例子,我们来看一下 H.264 编码器。 H.264 是 QuickTime 视频使用的视频编码。它还用于 MPEG 视频、许多 AVI,并且 Skype 也使用它。因为这种情况很常见,有人坐下来找到了一种在硬件中制作芯片的方法,您可以将编码文件输入到该芯片的一端,而红色、绿色和蓝色视频通道则从另一端输出。

在该芯片存在之前(以及在 Flash 10.1 之前),您必须使用软件对其进行解码。解码它涉及大量的正弦和余弦。正弦和余弦是超越函数(也就是说,没有无限级数,就无法将它们写成四种基本数学运算)。这意味着您能做的最好的事情就是运行循环 32-64 次,随着循环的每次迭代进行加法、乘法和除法,逐渐变得更加准确。循环的每次迭代也会将值移入和移出寄存器(正如您所记得的,这会消耗电力)。

Flash 过去通过在软件中对视频进行数学解码来解码视频。现在它只是说“将视频传递到H.264芯片”。当然,它还必须检查该芯片是否存在,如果不存在则使用软件。这意味着 Flash 作为一个整体现在变得更大了。但任何配备 H.264 芯片的系统(如 HTC 手机),现在都消耗更少的电量。

将相同的逻辑应用于:

  • 乘法(在软件中多次相加)
  • 模数(在软件中的无限级数)
  • 比较(在软件中减去并检查是否为负)
  • 绘图(在软件中的正弦/余弦/恶心。易于传递到视频卡)

There's actually one much bigger way to reduce power consumption that hasn't been touched on.

Let's take a computer and divide all functions into two basic groups. Those implemented in hardware and those implemented in software.

If a function is implemented in hardware (that is- there is circuitry for which you can put the inputs on one set of wires and the outputs come out another set of wires) then the power consumption is equal to the power consumed in the total number of gates. The clock ticks one time (draining a little power) and the bus goes hot for the output (draining a little power).

If a function is implemented in software (that is- there is no single circuit which is used to implement the function) then it requires the use of multiple circuits, multiple clock cycles, and often-times lots of memory calls. Keep in mind that SRAM (used for processor registers) is made of D flip-flops which are constantly draining power so long as they are in use.

As a simple example, let's look at the H.264 encoder. H.264 is a video encoding used by QuickTime videos. It's also used in MPEG videos, many AVIs, and it's used by Skype. Because it's so common someone sat down and found a way to make a chip in hardware to which you feed the encoded file on one end and the red, green, and blue video channels come out the other end.

Before this chip existed (and before Flash 10.1) you had to decode this using software. Decoding it involves lots of sines and cosines. Sine and cosine are transcendental functions (that is- there is no way to write them in the four basic math operations without an infinite series). This means that the best you could do what run a loop 32-64 times getting gradually more accurate, with each iteration of the loop adding, multiplying, and dividing. Each iteration of the loop also moves values in and out of registers (which- as you recall, uses power).

Flash used to decode video by mathematically decoding it in software. Now it just says "pass the video to the H.264 chip". Of course it also has to check for the existence of this chip and use software if it doesn't exist. This means Flash, as a whole, is now larger. But one any system (like HTC phones) with an H.264 chip, it now uses less power.

Apply this same logic for:

  • Multiplying (adding multiple times in software)
  • Modulus (an infinite series in software)
  • Comparing (subtracting and checking if negative in software)
  • Drawing (sines/cosines/nastiness in software. Easy to pass to a videocard)
鸵鸟症 2024-10-03 16:42:20

看起来这可能是针对嵌入式设备的,我敢说,节省电量的最佳方法是不开机,并尽量减少设备开机的时间。这意味着仅在需要完成工作时才将处理器置于睡眠状态并唤醒。我能想到的最好方法是使应用程序完全由中断驱动。

Seeing as though this is probably aimed towards embedded devices, I would venture to say that the best way to save power is to not be on, and to minimize how long the device is on. This means putting the processor to sleep and waking up only when work needs to be done. The best way I can think of to do this would to make an application entirely interrupt-driven.

你曾走过我的故事 2024-10-03 16:42:20

除了凯文的建议之外,我认为尽量减少互联网通信也会有所帮助。这包括批量获取数据,以便有更多的时间可以用来睡觉。

In addition to Kevin's suggestion, I would think that minimizing Internet communications would help. This would include fetching data in bulk so more time can be spent asleep.

樱娆 2024-10-03 16:42:20

另请记住,访问驱动器和 WiFi 等设备会增加功耗。尽量减少对此类设备的访问。

Also keep in mind that accessing devices like drives and wifi increases power consumption. Try to minimize access to such devices.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文