opyum 0.2

Creator: bradpython12

Last updated:

Add to Cart

Description:

opyum 0.2

# opyum[![version](https://img.shields.io/pypi/v/opyum.svg)](http://pypi.python.org/pypi/opyum)[![downloads](https://img.shields.io/pypi/dw/opyum.svg)](http://pypi.python.org/pypi/opyum)[![license](https://img.shields.io/pypi/l/opyum.svg)](http://pypi.python.org/pypi/opyum)[![status](https://img.shields.io/pypi/status/opyum.svg)](http://pypi.python.org/pypi/opyum)[![pyversions](https://img.shields.io/pypi/pyversions/opyum.svg)](http://pypi.python.org/pypi/opyum)## Description**Optimizing Python applications without mutilation code.** Use the automatic modification of AST for code optimization, which is transparent to the user and requires the addition of only a few lines.## Usage**Decorator**:```pythonfrom opyum import optimize@optimizedef function_for_optimize(): ...```**Import-hook**:```pythonimport opyumopyum.activate()# other imports```**"With" syntax:**```pythonimport opyumwith opyum.activate: # other imports```**Command-line mode:**Show optimized source: opyumshowmyfile.pyDiffbetweenoriginalsourceandoptimizedsource: opyum diff myfile.pyConsole diff (with "-c" or "--console" option):![console diff example](https://raw.githubusercontent.com/Amper/opyum/master/example/screen1.png)Custom app diff (with "--app" option):![app diff example](https://raw.githubusercontent.com/Amper/opyum/master/example/screen2.png)By default, html diff (without options):![app diff example](https://raw.githubusercontent.com/Amper/opyum/master/example/screen3.png)## List of optimizations####Constant foldingBefore:```pythonx = 7 * 24 * 60 * 60y = [i ** 2 for i in range(10) if i % 2 == 0]z = sum(range(1000))```After:```pythonx = 604800y = [0, 4, 16, 36, 64]z = 499500```####"'Power' to 'multiplication'" optimizationBefore:```pythonx1 = a ** (-2)x2 = a ** (-1)x3 = a ** ( 0)x4 = a ** ( 1)x5 = a ** ( 2)```After:```pythonx1 = 1 / (a * a)x2 = 1 / ax3 = 1x4 = ax5 = a * a```####"'Yield' to 'yield from'" optimizationBefore:```pythonfor x in some_expression: yield x```After```pythonyield from some_expression```####Builtin constant propagationBefore:```pythonfrom math import pidef circumference(r): return 2 * pi * r```After:```pythonfrom math import pidef circumference(r): return 2 * 3.141592653589793 * r```####Custom constant propagationBefore:```pythonC_PI = 3.141592653589793def circumference(r): return 2 * C_PI * r```After:```pythonC_PI = 3.141592653589793def circumference(r): return 2 * 3.141592653589793 * r```####Dead code eliminationBefore:```pythondef do_something(): return 1 print('returning 1')if condition1: passelif condition2: do_something()else: pass```After:```pythondef do_something(): return 1if not condition1 and condition2: do_something()```## InstallationInstallation is simple with pip: pipinstallopyumorwithsetuptools: easy_install opyum## Documentation [opyum.readthedocs.org](http://opyum.readthedocs.org/) [opyum.rtfd.org](http://opyum.rtfd.org/)

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.