Comments (3)
put some effort in and profile it
from reorder-python-imports.
I was wondering the same thing so for what it's worth, I did some profiling on my machine with the standardlib typing
and collections
modules.
I'm quite sure it doesn't matter in most cases but single line imports seem to be a bit slower and it's adding up the more import you have. For my use cases, it doesn't outweight the merge conflict management benefits provided by this style.
Typing (71 imports)
Full ipython snippet
%%timeit
from typing import Any
from typing import Callable
from typing import ClassVar
from typing import Final
from typing import ForwardRef
from typing import Generic
from typing import Literal
from typing import Optional
from typing import Protocol
from typing import Tuple
from typing import Type
from typing import TypeVar
from typing import Union
from typing import AbstractSet
from typing import ByteString
from typing import Container
from typing import ContextManager
from typing import Hashable
from typing import ItemsView
from typing import Iterable
from typing import Iterator
from typing import KeysView
from typing import Mapping
from typing import MappingView
from typing import MutableMapping
from typing import MutableSequence
from typing import MutableSet
from typing import Sequence
from typing import Sized
from typing import ValuesView
from typing import Awaitable
from typing import AsyncIterator
from typing import AsyncIterable
from typing import Coroutine
from typing import Collection
from typing import AsyncGenerator
from typing import AsyncContextManager
from typing import Reversible
from typing import SupportsAbs
from typing import SupportsBytes
from typing import SupportsComplex
from typing import SupportsFloat
from typing import SupportsIndex
from typing import SupportsInt
from typing import SupportsRound
from typing import ChainMap
from typing import Counter
from typing import Deque
from typing import Dict
from typing import DefaultDict
from typing import List
from typing import OrderedDict
from typing import Set
from typing import FrozenSet
from typing import NamedTuple
from typing import TypedDict
from typing import Generator
from typing import AnyStr
from typing import cast
from typing import final
from typing import get_args
from typing import get_origin
from typing import get_type_hints
from typing import NewType
from typing import no_type_check
from typing import no_type_check_decorator
from typing import NoReturn
from typing import overload
from typing import runtime_checkable
from typing import Text
from typing import TYPE_CHECKING
%%timeit
from typing import (
Any,
Callable,
ClassVar,
...
TYPE_CHECKING
namedtuple,
)
python38: 1.72 µs ± 9.93 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
python39: 1.71 µs ± 1.8 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
python310: 2.04 µs ± 42.1 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
python311: 2.22 µs ± 15.6 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
Full ipython snippet
%%timeit
from typing import (
Any,
Callable,
ClassVar,
Final,
ForwardRef,
Generic,
Literal,
Optional,
Protocol,
Tuple,
Type,
TypeVar,
Union,
AbstractSet,
ByteString,
Container,
ContextManager,
Hashable,
ItemsView,
Iterable,
Iterator,
KeysView,
Mapping,
MappingView,
MutableMapping,
MutableSequence,
MutableSet,
Sequence,
Sized,
ValuesView,
Awaitable,
AsyncIterator,
AsyncIterable,
Coroutine,
Collection,
AsyncGenerator,
AsyncContextManager,
Reversible,
SupportsAbs,
SupportsBytes,
SupportsComplex,
SupportsFloat,
SupportsIndex,
SupportsInt,
SupportsRound,
ChainMap,
Counter,
Deque,
Dict,
DefaultDict,
List,
OrderedDict,
Set,
FrozenSet,
NamedTuple,
TypedDict,
Generator,
AnyStr,
cast,
final,
get_args,
get_origin,
get_type_hints,
NewType,
no_type_check,
no_type_check_decorator,
NoReturn,
overload,
runtime_checkable,
Text,
TYPE_CHECKING,
)
%%timeit
from typing import Any
from typing import Callable
from typing import ClassVar
...
from typing import TYPE_CHECKING
python38: 27.8 µs ± 100 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
python39: 29.4 µs ± 208 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
python310: 30.2 µs ± 79.7 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
python311: 45.3 µs ± 920 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
Collections (9 imports)
%%timeit
from collections import (
ChainMap,
Counter,
OrderedDict,
UserDict,
UserList,
UserString,
defaultdict,
deque,
namedtuple,
)
python38: 900 ns ± 4.13 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
%%timeit
from collections import ChainMap
from collections import Counter
from collections import OrderedDict
from collections import UserDict
from collections import UserList
from collections import UserString
from collections import defaultdict
from collections import deque
from collections import namedtuple
python38: 2.44 µs ± 71.8 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
from reorder-python-imports.
you've just spent more time on this comment than has ever been spent on the difference in imports
from reorder-python-imports.
Related Issues (20)
- Gracefully handle try, except blocks in imports HOT 3
- multiline import from same package? HOT 2
- Option to disable reordering HOT 4
- Support for pyi files now types_or is implemented HOT 3
- distutils ordered as a third-party package HOT 1
- Not numerically sorting HOT 2
- Sylink dirs treated as 3rd party modules HOT 6
- Option to disable import replacement HOT 1
- triple-quoted docstring with trailing backslash silently prevents reordering HOT 2
- disable remove duplicates in argument HOT 1
- Support for ignoring certain files HOT 1
- Removes blank lines between comments HOT 2
- Relative import ordering HOT 10
- add-import with module without imports HOT 1
- Adding prober ignore files HOT 1
- can you please add the lxml library. HOT 9
- Support pyproject.toml
- winreg missing from six._moved_attributes on non-Windows platforms
- Better support for `_typeshed` imports HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reorder-python-imports.