Introduction: ESP8266 - NodeMCU - CPU Speed Test

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!