问题描述
是否有一种方法可以计算加载和呈现网页(前端)所消耗的电量?我在想用phantomjs进行的测试",例如:
Is there a way to calculate the electricity consumed to load and render a webpage (frontend)? I was thinking of a 'test' made with phantomjs for example:
- 加载网页
- 滚动到底部
并测量需要多少电量.我也许可以从CPU周期推断出来.但是phantomjs毫无头绪,在实际的浏览器中渲染肯定有所不同.也许不可能进行真正的测量..但是有了索引,就有可能比较网站.
And measure how much electricity was needed. I can perhaps extrapolate from CPU cycle. But phantomjs is headless, rendering in real browser is certainly different. Perhaps it's impossible to do real measurements.. but with an index it may be possible to compare websites.
还有其他建议吗?
推荐答案
用现代处理器(比286更新的任何东西)在内部进行测量几乎是不可能的.在内部,我指的是计算周期.这是因为处理器的不同部分根据指令每个周期消耗不同级别的能量.
It's pretty much impossible to measure this internally in modern processors (anything more recent than 286). By internally, I mean by counting cycles. This is because different parts of the processor consume different levels of energy per cycle depending upon the instruction.
也就是说,您可以进行测量.将功率计插入墙壁和处理器之间.这是一个过程:
That said, you can make your measurements. Stick a power meter between the wall and the processor. Here's a procedure:
- 测量基准能耗,即除了操作系统和浏览器之外,没有任何运行的设备,并且浏览器完全静态(即不执行任何操作).您需要确保一切都处于稳定状态(SS),这意味着仅在闲置几分钟后才能开始测量.
- 测量所需操作的使用量.同样,您要避免任何启动和停止工作,因此请确保在开始操作后至少15秒钟开始测量.停止不是问题,因为完成测量后浏览器将执行任何终止代码.
听起来很简单,对吧?不幸的是,由于测量的性质,存在一些陷阱.
Sounds simple, right? Unfortunately, because of the nature of your measurements, there are some gotchas.
您还记得您讲过信噪比的物理课程(或EE课程)吗?向下滚动会消耗很少的能量,因此信号(向下滚动)在噪声中会很好(正常背景处理).这意味着您必须取样很多以获得有用的东西.
Do you recall your physics classes (or EE classes) that talked about signal to noise ratios? Well, a scroll down uses very little energy, so the signal (scrolling) is well in the noise (normal background processes). This means you have to take a LOT of samples to get anything useful.
您的浏览器启动能耗或使用相当数量处理量的其他任何事物,都更易于测量(更好的信噪比).
Your browser startup energy usage, or anything else that uses a decent amount of processing, is much easier to measure (better signal to noise ratio).
此外,请确保您了解基本的电子设备.例如,功率是VA(电压*安培数),其中V和A都同相.我不认为这会成为问题,因为我很确定它们已经在计算机阶段.而且,任何体面的功率计都可以理解它们之间的区别.
Also, make sure you understand the underlying electronics. For example, power is VA (voltage*amperage) where both V and A are in phase. I don't think this will be an issue since I'm pretty sure they are in phase for computers. Also, any decent power meter understands the difference.
我猜您打算在移动设备上执行此操作.每个处理器的测量结果大致相同.这是由于代代之间以及制造商之间的体系结构差异.
I'm guessing you intend to do this for mobile devices. Your measurements will only be roughly the same from processor to processor. This is due to architectural differences from generation to generation, and from manufacturer to manufacturer.
祝你好运.
这篇关于测量浏览器渲染网页所消耗的电量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!