MicroPython Startup Time
MicroPython Startup Time
I have been doing some timing measurements on an ESP32 MicroPython application that spends most of the time in deep sleep. The board (a TinyPICO) takes 1.67 seconds to reach main.py from wakeup. Does this sound reasonable given that MicroPython boots to essentially the same place in 150 microseconds on a Pyboard? Why the big difference?
-
- Posts: 169
- Joined: Fri Aug 19, 2016 11:55 am
Re: MicroPython Startup Time
This has been discussed on Discord:
https://discordapp.com/channels/6056217 ... 8651969537
https://discordapp.com/channels/6056217 ... 3429890058
https://discordapp.com/channels/6056217 ... 8651969537
https://discordapp.com/channels/6056217 ... 3429890058
UnexpectedMaker wrote:Time to boot the TinyPICO and get into MicroPython is hampered by the RAM test that the IDF does on the extra PSRAM during init - That can be turned off, but requires you to make a custom MicroPython firmware.
Re: MicroPython Startup Time
@Christian, thanks for the links. I was not aware of those discussions.
My application is a small one and I don't think I need the PSRAM. I will try a non-SPIRAM ESP32 firmware and see if that improves matters.
Paul
My application is a small one and I don't think I need the PSRAM. I will try a non-SPIRAM ESP32 firmware and see if that improves matters.
Paul
Re: MicroPython Startup Time
Hey Paul, please report back - I'd be curious to know what the startup time is on an ESP32 w/o PSRAM. Thanks!
Re: MicroPython Startup Time
Pyboard is fast but maybe not that fast. Could it be 150 ms?MicroPython boots to essentially the same place in 150 microseconds on a Pyboard?
Re: MicroPython Startup Time
Hi guys,
I flashed the generic non-spiram esp32 firmware (esp32-idf3-20190529-v1.11.bin) into my TinyPICO, reloaded the app files and repeated the test. The time from wakeup to reaching main.py is now 612ms. That is over 1 second faster than before.
For completeness I should say that my application is a battery powered remote sensor. It is woken up by a button press. It connects to Wi-Fi, gets the time from the network, reads the sensor, briefly displays the reading on an OLED display and then goes back to deep sleep. The application will also transmit the readings to a host, but I haven't coded that bit yet. I am measuring the run time with led2.on() at the start of main.py and led2.off() immediately before calling deepsleep.
I am measuring the startup time using a digital scope. One channel is connected to the button GPIO, the other to led2 GPIO. The scope is triggered by a falling edge on the button input and is in single sweep mode. I am using the cursors to measure the time delay between the falling edge of the button input and the rising edge of led2 output.
With normal python files, the run takes 4.94 seconds. I switched to using pre-compiled bytecode and that shaved 400 milliseconds off the run time.
The startup time saving is significant. It will extend the battery life by around 3 days.
@Roberthh, the following statement is taken from the home page of micropython.org. I have no reason to believe it's not true.
fast start-up time from boot to loading of first script (150 microseconds to get to boot.py, on PYBv1.1 running at 168MHz)
I flashed the generic non-spiram esp32 firmware (esp32-idf3-20190529-v1.11.bin) into my TinyPICO, reloaded the app files and repeated the test. The time from wakeup to reaching main.py is now 612ms. That is over 1 second faster than before.
For completeness I should say that my application is a battery powered remote sensor. It is woken up by a button press. It connects to Wi-Fi, gets the time from the network, reads the sensor, briefly displays the reading on an OLED display and then goes back to deep sleep. The application will also transmit the readings to a host, but I haven't coded that bit yet. I am measuring the run time with led2.on() at the start of main.py and led2.off() immediately before calling deepsleep.
I am measuring the startup time using a digital scope. One channel is connected to the button GPIO, the other to led2 GPIO. The scope is triggered by a falling edge on the button input and is in single sweep mode. I am using the cursors to measure the time delay between the falling edge of the button input and the rising edge of led2 output.
With normal python files, the run takes 4.94 seconds. I switched to using pre-compiled bytecode and that shaved 400 milliseconds off the run time.
The startup time saving is significant. It will extend the battery life by around 3 days.
@Roberthh, the following statement is taken from the home page of micropython.org. I have no reason to believe it's not true.
fast start-up time from boot to loading of first script (150 microseconds to get to boot.py, on PYBv1.1 running at 168MHz)
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: MicroPython Startup Time
You may find that using frozen bytecode saves a bit more time by removing the need to access the filesystem.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: MicroPython Startup Time
I made a little test, adding a pin toggle statement just at the start of boot.py. The code consist of:fast start-up time from boot to loading of first script (150 microseconds to get to boot.py, on PYBv1.1 running at 168MHz)
Code: Select all
from machine import Pin
p=Pin("X9", Pin.OUT, value=1)
p(0)
p(1)
Re: MicroPython Startup Time
@Roberthh which board did you use for your test?
I agree with you that 8.4ms is a very respectable result.
So where did the 150us come from? Could it be that Damien made a mistake and nobody thought to question it or double check it?
I agree with you that 8.4ms is a very respectable result.
So where did the 150us come from? Could it be that Damien made a mistake and nobody thought to question it or double check it?
Re: MicroPython Startup Time
As told: Pyboard V1.1 @ 168MHz