timeit2
このパッケージは処理時間の計測module timeit を使いやすくしたものです。以下の特徴があります。
- 引数を使い回しません(timeitは引数を書き換える処理をした時にそのまま次に渡します)
- 複数の関数を1度に計測して相対的な速度差を視覚化できます
- 処理時間の桁数を変えられます(0.00374567より0.0037の方が見やすい)
- 返り値を一緒にprintできます
Install
$ pip install timeit2
Example
from timeit2 import ti2
arg = range(10 ** 6)
ti2(
max,
sum,
args=[arg],
floor=4,
print_return=True,
return_label="ret: ",
relative=True,
)
# max:
# 0.0356 sec
# ret: 999999
# sum:
# 0.0249 sec
# ret: 499999500000
# relative:
# sum:
# 1
# max:
# 1.43
最小限の使い方
from timeit2 import ti2
def f():
li = []
for i in range(10 ** 5):
li.append(i * i)
return li
ti2(f)
# f:
# 0.015094 sec
配列作成にlist.append,list.insert,dequeをそれぞれ使った処理時間と相対評価
from collections import deque
from timeit2 import ti2
def append_(n):
li = []
for i in range(n):
li.append(i)
return li
def insert_(n):
li = []
for i in range(n):
li.insert(0, i)
return li
def deque_right(n):
li = deque()
for i in range(n):
li.append(i)
return li
def deque_left(n):
li = deque()
for i in range(n):
li.appendleft(i)
return li
ti2(
append_,
insert_,
deque_right,
deque_left,
args=[10 ** 4],
relative=True,
)
# append_:
# 0.001118 sec
# insert_:
# 0.021187 sec
# deque_right:
# 0.000891 sec
# deque_left:
# 0.000855 sec
# relative:
# deque_left:
# 1
# deque_right:
# 1.04
# append_:
# 1.31
# insert_:
# 24.77
API
ti2(
*fn: Callable,
args: list = [],
number: int = 100,
floor: int = 6,
relative: bool = False,
print_return: bool = False,
return_label: str = "",
)
argument
fn
Type: Callable
計測する関数、可変長引数なので複数指定が可能。
引数がある場合はargs= で指定する。
Options
args
Type: list
Default: []
fnに渡す引数のlist
number
Type: int
Default: 100
各関数を計測する回数、結果はその最速値が表示される
floor
Type: int
Default: 6
表示する小数点以下の桁数
relative
Type: bool
Default: False
計測結果に相対評価を追加する
print_return
Type: bool
Default: False
計測結果に関数の返り値を追加する
return_label
Type: str Default: ""
print_return=Trueの場合、返り値のラベルを指定する
alias
ti2, ti, timeit, timeit2 をimportできますが、全て同じものです。
from timeit2 import ti2, ti, timeit, timeit2
Related
License
MIT © 2021 atu4403
Metadata
Release files for timeit2 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| timeit2-1.0.0.tar.gz | 3.7 kB | Without provenance | Details for timeit2-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| timeit2-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for timeit2-1.0.0-py3-none-any.whl |
Total release size: 6.9 kB
Release files / timeit2-1.0.0.tar.gz
| Download URL | timeit2-1.0.0.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
737344bc80eb06cbd03e84aa67355d21b166eb6d277cd5997c8b0e87a8f6b84a
|
|
BLAKE2b-256 checksum How to use checksums |
e414c2afd7b2e1ef3e5fb2fa56b885ed4f029ff7f611b757dbe955f5083babd5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.8.12 Darwin/18.7.0
|
Release files / timeit2-1.0.0-py3-none-any.whl
| Download URL | timeit2-1.0.0-py3-none-any.whl |
|---|---|
| Size | 3.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dd553c76177e844d0bea23e0a98d233a828f0e97e5ff4579915b63536e31b561
|
|
BLAKE2b-256 checksum How to use checksums |
11a82aa7599e8d1f29cda32bed4c8de523e96993f91f531479d5839739e89c2c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.8.12 Darwin/18.7.0
|
Security for timeit2 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.