电池安全编码 [英] Battery-safe coding

查看:160
本文介绍了电池安全编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一些规则或提示如何在编码时直接防止电池耗尽。我知道可能有一些方法可以编写代码来最小化处理器上的工作负载或防止泄漏。但是,除了像位置服务和互联网连接这样的常见嫌疑人之外,有没有人像导游或类似清单之类的东西?

I was wondering if there are some rules or hints how to prevent battery drain directly while coding. I know that there may be some ways to code to minimize workload on the processor or prevent leaks. However, does anybody have something like a guide or a something like a "checklist" besides the usual suspects like location service and internet connection?

推荐答案

我认为你的意思是你的申请。根据我的经验,能源的主要消费者是#1最重要的:

I'll assume you mean your application. In my experience, the major consumers of energy are, where #1 is most important:


  1. CPU使用率

  2. 4G

  3. WiFi

  4. 蓝牙

  5. 内存

  1. CPU usage
  2. 4G
  3. WiFi
  4. Bluetooth
  5. Memory

4G或WiFi是否更糟糕取决于您的使用情况,例如:您是通过蜂窝网络与信号不良交谈,还是通过WiFi传输视频。 GPS取决于您是否正在使用它。如果你正在转弯方向,它会把你的手机变成一个小加热器并快速耗尽你的电池。

Whether 4G or WiFi is worse depends upon your usage, e.g. whether you are talking with a poor signal over your cellular network or are streaming video over your WiFi. GPS depends upon if you are using it. If you are getting turn by turn directions, it'll turn your phone into a little heater and drain your battery very quickly.

最小化4G,WiFi和蓝牙的使用是很直接。我不确定是否有可能以任何实际的方式减少内存使用的能量。

Minimizing 4G, WiFi, and Bluetooth usage is pretty straight forward. I not sure it's possible to reduce the energy used by memory in any practical way.

CPU使用率是最大的潜在能量消耗因为它可以持续吸收所有的电子能量时间。值得庆幸的是,现代处理器在什么也不做的时候关闭,即空转。这称为进入空闲/ C状态。你可以猜到,手机大部分时间都没有做任何事情。

CPU usage is the greatest potential energy hog because it can continuously suck down electrons all of the time. Thankfully, modern processors shut down when doing nothing, i.e. idling. This is called dropping into an idle / C-state. As you can guess, a cell phone is doing nothing pretty much most of the time.

你可以通过多种方式编写程序来最大限度地减少CPU能耗。实际上,更好的说法是,有些方法可以通过编写程序错误来击败这些节能功能。如果CPU进入休眠状态以最小化功率,那么唤醒它会增加能量消耗。另一个需要考虑的因素是CPU处于睡眠状态的时间。您可以让处理器空闲的时间越长,它可以进入的睡眠状态就越深,而更深的睡眠状态则会消耗更少的能量。

There are ways you can write your program to minimize CPU energy usage. Actually, a better way of saying this is that there are ways you can defeat these energy saving features by writing your program wrong. If the CPU goes to sleep to minimize power then waking it up increases energy usage. Another factor to consider is how long the CPU is asleep. The longer you can leave the processor idle, the deeper a sleep state it can enter, and deeper sleep states use less power.

那么你需要做些什么来最小化你的CPU使用率?您希望减少使用CPU,或者以另一种方式说,让您的程序完成任何更快的操作。此外,增加程序空闲的时间长度。

So what do you need to do to minimize your CPU usage? You want to use the CPU less, or to say it another way, have your program get done whatever it’s doing faster. Also, increase the length of time that your program is idle.

现在让我们来看看你可以做的具体事情:

Now let's take a look at some concrete things you can do:


  1. 让你的程序尽可能快地完成它正在做的事情。通过找到最快的算法并以尽可能最有效的方式实现它来做到这一点。换句话说,优化。

  1. Have your program do whatever it's doing as fast as possible. Do this by finding the fastest algorithm and implementing it in the most efficient way possible. To say it another way, optimize.

尽量减少对事件的检查。检查事件是否发生的次数越多,唤醒处理器的次数越多,进入真正深度睡眠状态的可能性就越小。通过计算在保持性能的同时检查某些事件的最大间隔来做到这一点。

Minimize checking on events. The more you check on whether an event occurred, the more you wake up the processor, the less likely it can drop into a really deep sleep state. Do this by figuring out the maximum interval that you have to check for some event while still maintaining performance.

这篇关于电池安全编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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