loading

Simply put, faster CPUs complete more calculations, more lines of code and more house keeping tasks in a given period of time.

Theoretically, a CPU running at twice the speed should complete a task in about one half the time. Faster!

The latest version of NodeMCU has the ability to adjust the ESP8266's CPU frequency.

The default speed for the ESP8266 is 80 MHZ. NodeMCU now lets you toggle, at run-time, whether the CPU should run at the default 80 MHZ or twice as fast at 160 MHZ.

The Command is: node.setcpufreq()

For 80 MHZ: node.setcpufreq(node.CPU80MHZ)

For 160 MHZ: node.setcpufreq(node.CPU160MHZ)

80Mhz and 160Mhz are the only options.

Does this really work? Lets see.

Step 1: Lua Code.

I flashed a ESP8266-01 with the latest version of NodeMCU: nodemcu_integer_0.9.6-dev_20150704.bin

I created a lua file called 'speedtest.lua':

print(" Test will loop 1,000,000 times @ 160Mhz,\n and again @ 80Mhz.")
print("Starting test ---------------\n")

print("\n+++++++++++++++\n")
print("node.setcpufreq(node.CPU160MHZ)")
node.setcpufreq(node.CPU160MHZ)
print(tmr.now())

starttime = tmr.now()
local i = 1
while i < 1000000 do
i = i + 1
end
print(tmr.now())
endtime = tmr.now()

print("Total time @160MHZ "..endtime - starttime.. " Microseconds")
collectgarbage()
tmr.wdclr()
print("\n+++++++++++++++\n")
print("node.setcpufreq(node.CPU80MHZ)")
node.setcpufreq(node.CPU80MHZ)
print(tmr.now())
collectgarbage()
starttime = tmr.now()
local i = 1
while i < 1000000 do
i = i + 1
end
print(tmr.now())
endtime = tmr.now()
print("Total time @80MHZ "..endtime - starttime.. " Microseconds")
print("\n End of test.")
collectgarbage()

Step 2: Results:

dofile(speedtest.lua) Friday, August 07, 2015 08:37:55

dofile("speedtest.lua")

Test will loop 1,000,000 times @ 160Mhz, and again @ 80Mhz.

Starting test ---------------

node.setcpufreq(node.CPU160MHZ)

1517836198
1519473254

Total time @160MHZ 1626061 Microseconds

+++++++++++++++

node.setcpufreq(node.CPU80MHZ)

1519478214
1522730804

Total time @80MHZ 3251941 Microseconds

End of test.

> node.compile("speedtest.lua") >

dofile(speedtest.lc) Friday, August 07, 2015 08:38:12

dofile("speedtest.lc")

Test will loop 1,000,000 times @ 160Mhz, and again @ 80Mhz. Starting test ---------------

node.setcpufreq(node.CPU160MHZ)

1534796621
1536433701

Total time @160MHZ 1626101 Microseconds

+++++++++++++++

node.setcpufreq(node.CPU80MHZ)

1536438677
1539691273

Total time @80MHZ 3251938 Microseconds

End of test.

Step 3: Some Observations:

The test results are clear, the ESP8266 is performing the loop twice as fast!

Although, I have not done extensive testing, I believe that once the CPU is set to 160 MHZ, it will stay at that speed until rebooted or reset. I did run similar tests in other files called from within lua files.

Putting - node.setcpufreq(node.CPU160MHZ) - in the init.lua should be good to go.

This test was conducted with the 'integer' version of the firmware. The same files in the 'float' version provided similar output, however I did have to reduce the loop from 1,000,000 to 100,000 to keep the ESP from rebooting.

I find NodeMCU to be an extremely reliable firmware and it appears that work is ongoing for even more improvements.

It bears watching!

<p>Hi, I look my card ESP8266-12E and the quartz is a 26 Mhz ? why</p>
<p>Hi,it's because PLL unit.</p><p>with PLL you can increase the system clock when you need and also decrease it when you wish to save power. </p>
<p>Here is my very unscientific evaluation of power consumption.</p><p>This script:</p><p>node.setcpufreq(node.CPU80MHZ)<br>--node.setcpufreq(node.CPU160MHZ)</p><p>x=0<br>while x &lt; 5 do<br>gpio.mode(0,gpio.OUTPUT)<br>gpio.write(0,gpio.LOW)<br>tmr.delay(250000)<br>gpio.write(0,gpio.HIGH)<br>tmr.delay(250000)<br>gpio.write(0,gpio.LOW)<br>tmr.delay(250000)<br>gpio.write(0,gpio.HIGH)<br>tmr.delay(250000)<br>gpio.write(0,gpio.LOW)<br>tmr.delay(650000)<br>gpio.write(0,gpio.HIGH)<br>tmr.delay(250000)<br>gpio.write(0,gpio.LOW)<br>tmr.delay(250000)<br>gpio.write(0,gpio.HIGH)<br>x = x + 1<br>end</p><p>80Mhz<br>89 - 90 mA while in the loop.<br>33 - 34 mA idle after the loop.</p><p>160Mhz<br>94.8 - 95 mA while in the loop.<br>34 - 35 mA idle after the loop.</p><p>Also, I got identical results when running the original script in this Instructable.</p><p>Hope this helps.</p>
<p>What about power consumption?</p>

About This Instructable

14,699views

21favorites

License:

More by breagan22:ESP8266 WiFi OTA Remote File Management ESP8266 - NodeMCU - CPU Speed Test ESP8266 Irrigation Controller / Echo Alexa integration 
Add instructable to: