GithubHelp home page GithubHelp logo

tryingsnake's People

Contributors

mfcabrera avatar zero323 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

bennyelg

tryingsnake's Issues

Performance regression caused by type hints

It seems like adding type annotations (#5)

class Try_(Generic[T]):

caused rather unexpected performance regression:

Python 3.8.0 | packaged by conda-forge | (default, Nov 22 2019, 19:11:38) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.11.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import importlib                                                                                

In [2]: !git checkout 3a25dba30a527476deb4bfbd3cfa88ccd2b977ee                                          
Note: switching to '3a25dba30a527476deb4bfbd3cfa88ccd2b977ee'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 3a25dba Provide type annotations and apply required refactoring

In [3]: import tryingsnake                                                                              

In [4]: %timeit for i in range(1_000): tryingsnake.Try(lambda x: x, 1)                                  
1.36 ms ± 12.3 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

In [5]: !git checkout HEAD~1                                                                            
Previous HEAD position was 3a25dba Provide type annotations and apply required refactoring
HEAD is now at a666744 Merge pull request #4 from zero323/failed

In [6]: importlib.reload(tryingsnake)                                                                   
Out[6]: <module 'tryingsnake' from '/path/to/tryingsnake/tryingsnake/__init__.py'>

In [7]: %timeit for i in range(1_000): tryingsnake.Try(lambda x: x, 1)                                  
668 µs ± 6.82 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

It seems that the main culprit is Generic[T] added as a base class for Try_.

asciicast

Such overhead is rather unacceptable in practice, so unless it is considered a bug, and solved upstream, we should probably move annotations to stub files (401ec6f).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.