timeit function not available in machine module

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
giri
Posts: 4
Joined: Wed Nov 06, 2019 4:47 pm

timeit function not available in machine module

Post by giri » Thu Nov 07, 2019 2:43 pm

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

User avatar
jimmo
Posts: 830
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: timeit function not available in machine module

Post by jimmo » Thu Nov 07, 2019 8:47 pm

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

User avatar
Roberthh
Posts: 1718
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: timeit function not available in machine module

Post by Roberthh » 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.

giri
Posts: 4
Joined: Wed Nov 06, 2019 4:47 pm

Re: timeit function not available in machine module

Post by giri » Sat Nov 09, 2019 9:03 am

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

giri
Posts: 4
Joined: Wed Nov 06, 2019 4:47 pm

Re: timeit function not available in machine module

Post by giri » Sat Nov 09, 2019 9:05 am

jimmo wrote:
Thu Nov 07, 2019 8:47 pm
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
Thanks
I will check

User avatar
pythoncoder
Posts: 3669
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: timeit function not available in machine module

Post by pythoncoder » 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)
Peter Hinch

giri
Posts: 4
Joined: Wed Nov 06, 2019 4:47 pm

Re: timeit function not available in machine module

Post by giri » Thu Nov 14, 2019 3:16 pm

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

Post Reply