kopia lustrzana https://github.com/micropython/micropython
Updated Improving performance with Viper code (markdown)
rodzic
a611800bac
commit
6bcc344b65
|
@ -53,7 +53,7 @@ All things nice that MicroPython does, will continue to work. What is affected i
|
|||
|
||||
# @micropython.viper vs. @micropython.native decorator
|
||||
|
||||
The @micropython.native decorator is another means to speeds up code, but does not require special data types or constructs. It covers most of the MicroPython language functionality without change, except a very few restrictions.
|
||||
The @micropython.native decorator is another means to speed up code, but does not require special data types or constructs. It covers most of the MicroPython language functionality without change, except a very few restrictions.
|
||||
|
||||
When not using the viper data types, performance of viper and native is similar. In fact, the viper code emitter is an extension of the native code emitter. However since most code has at least some integer variables, viper code may be faster than native code, sometimes even without change.
|
||||
|
||||
|
@ -96,7 +96,7 @@ In case you are familiar with C: The viper data types are similar to some C lang
|
|||
|`uint` | `unsigned long int`| 32 bit unsigned integer |
|
||||
|`ptr32` | `*long int` | memory pointer to a 32 bit signed integer |
|
||||
|`ptr16` |`*unsigned short int` |memory pointer to a 16 bit unsigned integer |
|
||||
|`ptr8` | `*unsigned char`|memory pointer to a 8 bit unsigned integer |
|
||||
|`ptr8` | `*unsigned char`|memory pointer to an 8 bit unsigned integer |
|
||||
|
||||
## What to remember about viper data types
|
||||
|
||||
|
@ -118,7 +118,7 @@ It is advisable to be aware at all times that `viper int` and `builtins.int` are
|
|||
### Viper integer constants
|
||||
Viper integer constants are in the range -2\*\*29 to 2\*\*29-1. When you assign a viper constant to a variable, it automatically is a viper `int`.
|
||||
|
||||
Be aware: integer constants don't have the full range of values a viper int value can hold, they are signed 31 bit integers.
|
||||
Be aware: integer constants don't have the full range of values a viper int value can hold, they are signed 30 bit integers.
|
||||
|
||||
Integer expressions are evaluated compile time and reduced to a constant.
|
||||
|
||||
|
@ -236,7 +236,7 @@ The \*\* operator (exponentiation, `__pow__`) is not implemented for viper ```in
|
|||
|
||||
### int() casting
|
||||
|
||||
Within viper decorated functions, the int() function will cast an expression o a viper `int`. Examples:
|
||||
Within viper decorated functions, the int() function will cast an expression to a viper `int`. Examples:
|
||||
```py
|
||||
x = int(len(some_array)) # Many MicroPython functions return builtins.int
|
||||
x = int(2**30) # \*\* is not implemented for viper int and returns a builtins.int
|
||||
|
@ -618,7 +618,7 @@ A cause of this can be doing, for example, `int("1234")`. The viper `int()` is a
|
|||
# Some interesting links
|
||||
The official documentation: https://docs.micropython.org/en/v1.9.3/pyboard/reference/speed_python.html
|
||||
|
||||
Damien George's talk on MicroPythgon performance: https://www.youtube.com/watch?v=hHec4qL00x0
|
||||
Damien George's talk on MicroPython performance: https://www.youtube.com/watch?v=hHec4qL00x0
|
||||
|
||||
Interesting discussion about viper, parameters and optimization. Also see Damien George's comment on viper data types and casting: https://forum.micropython.org/viewtopic.php?f=2&t=1382
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue