Page 1 of 1
timeit function not available in machine module
Posted: Thu Nov 07, 2019 2:43 pm
by giri
I went through some posts here but could not find them helpful
I used esptool for importing micropython into my wemos D1 mini
However, I'm trying to find a way to calculate code execution time using in-built function 'timeit',
but it's not there
Anybody found a solution for this
Thanks
Re: timeit function not available in machine module
Posted: Thu Nov 07, 2019 8:47 pm
by jimmo
To save space, MicroPython doesn't include the whole of the Python standard library.
However you can install some things (including timeit) manually from micropython-lib -- e.g.
https://github.com/micropython/micropyt ... ter/timeit
Re: timeit function not available in machine module
Posted: Thu Nov 07, 2019 9:02 pm
by Roberthh
That timeit function in the micropython-lib looks like overkill, and certainly not made for esp8266.
In that situation, I usually time a function using utime.ticks_us() and utime.ticks_diff().
Edit: I faintly remember that Dave @dhylands had written something more reusable, but than might have been for the old PyBoard API.
Re: timeit function not available in machine module
Posted: Sat Nov 09, 2019 9:03 am
by giri
Roberthh wrote: ↑Thu Nov 07, 2019 9:02 pm
That timeit function in the micropython-lib looks like overkill, and certainly not made for esp8266.
In that situation, I usually time a function using utime.ticks_us() and utime.ticks_diff().
Edit: I faintly remember that Dave @dhylands had written something more reusable, but than might have been for the old PyBoard API.
Ok I will test it
Re: timeit function not available in machine module
Posted: Sat Nov 09, 2019 9:05 am
by giri
Re: timeit function not available in machine module
Posted: Sat Nov 09, 2019 9:16 am
by pythoncoder
You'll find a way to time a function call using a decorator
here e.g.
Code: Select all
@timed_function
def test():
utime.sleep_us(10000)
Re: timeit function not available in machine module
Posted: Thu Nov 14, 2019 3:16 pm
by giri
pythoncoder wrote: ↑Sat Nov 09, 2019 9:16 am
You'll find a way to time a function call using a decorator
here e.g.
Code: Select all
@timed_function
def test():
utime.sleep_us(10000)
Ok
I'll test
Thanks
In case of any doubt I'll get back to you