# ESP8266 - NodeMCU - CPU Speed Test

17,726

22

7

Posted

## 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 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 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!

## Recommendations

105 Enrolled

• ### Science of Cooking

We have a be nice policy.

## Questions

Hi, I look my card ESP8266-12E and the quartz is a 26 Mhz ? why

Hi,it's because PLL unit.

with PLL you can increase the system clock when you need and also decrease it when you wish to save power.

Here is my very unscientific evaluation of power consumption.

This script:

node.setcpufreq(node.CPU80MHZ)
--node.setcpufreq(node.CPU160MHZ)

x=0
while x < 5 do
gpio.mode(0,gpio.OUTPUT)
gpio.write(0,gpio.LOW)
tmr.delay(250000)
gpio.write(0,gpio.HIGH)
tmr.delay(250000)
gpio.write(0,gpio.LOW)
tmr.delay(250000)
gpio.write(0,gpio.HIGH)
tmr.delay(250000)
gpio.write(0,gpio.LOW)
tmr.delay(650000)
gpio.write(0,gpio.HIGH)
tmr.delay(250000)
gpio.write(0,gpio.LOW)
tmr.delay(250000)
gpio.write(0,gpio.HIGH)
x = x + 1
end

80Mhz
89 - 90 mA while in the loop.
33 - 34 mA idle after the loop.

160Mhz
94.8 - 95 mA while in the loop.
34 - 35 mA idle after the loop.

Also, I got identical results when running the original script in this Instructable.

Hope this helps.