-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
274 lines (185 loc) · 7.47 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
from setuptools import setup, find_packages
setup(
name="FFpy",
version="1.6.1",
packages=find_packages(),
install_requires=[
"tabulate",
],
entry_points={
"console_scripts": [
"ffpy = ffpy.timer:main",
],
},
description="Fast Python Script Execution Timer",
long_description="""
FFpy - ⚡ Fast Python Script Execution Timer
============================================
FFpy is a command-line tool that measures the execution time of Python
scripts. It provides flexibility by allowing you to specify the time
unit (milliseconds or seconds) and the number of runs for more accurate
measurements.
Background 🚀
-------------
As an undergraduate software engineer with Python as my weapon of choice
for coding, I often found myself curious about the execution time of my
scripts. While solutions like ``timeit`` module exist, I wanted a
seamless way to measure execution time without adding another line of
code to my programs. This led to the creation of FFpy.
In my coding journey, especially while tackling Data Structures and
Algorithms problems and optimizing code, understanding the execution
time can provide valuable insights.
FFpy aims to be a simple yet powerful tool for easily benchmarking
performance without the need to modify your existing codebase. I believe
in keeping things straightforward. FFpy is designed to be a
minimalistic, no-nonsense module that integrates seamlessly into your
workflow, allowing you to focus on coding while effortlessly obtaining
execution time metrics.
Installation 🛠️
---------------
Install FFpy using ``pip``:
.. code:: bash
pip install ffpy
Alternatively, you can clone this repository:
.. code:: bash
git clone https://github.com/anxkhn/FFpy.git
cd FFpy
pip install .
Usage 🚨
--------
After installation, you can use FFpy to measure the execution time of
your Python scripts. Here’s the basic syntax:
.. code:: bash
ffpy <filename.py/folder> <filename2.py> [-u <unit>] [-n <num_runs>] [-s] [-m <mode>] [-v] [-h]
- ``<filename.py/folder>``: Replace with the actual filename or folder of your Python script(s) in the current directory.
- ``<filename2.py>``: Optional second script for comparison.
- ``-u, --unit``: Optional flag to specify the time unit (ms or s,
default is ms).
- ``-n, --number``: Optional flag to specify the number of runs
(default is 1).
- ``-s, --silent``: Optional flag to run the script silently (suppress
output).
- ``-m, --mode``: Optional flag to specify the threads (single or
multi, default is single).
- ``-v, --version``: Display script version.
- ``-h, --help``: Display help message.
Examples 🌈
~~~~~~~~~~~
1. Measure the execution time of a script in milliseconds:
.. code:: bash
ffpy script.py
2. Measure the execution time in seconds:
.. code:: bash
ffpy script.py -u s
3. Run the script 10 times and measure the average execution time:
.. code:: bash
ffpy script.py -n 10
4. Run the script silently:
.. code:: bash
ffpy script.py -s
5. Run scripts concurrently using multithreading mode:
.. code:: bash
ffpy script.py -m multi
**Note on Multithreading Mode:**
When using the multithreading mode (``-m multi``), the script will be
executed concurrently in a multithreaded fashion, leveraging multiple
cores on your system. It’s important to note that the average execution
time in multithreading mode may not be equal to running the program
once, as multithreading introduces parallelism and can lead to
variations in execution times. `Learn more [1] about
multithreading. <https://github.com/anxkhn/FFpy/blob/main/learn_more.md#1-learn-more-about-multithreading-and-how-it-works>`__
Types of Operation:
-------------------
- **Single File:** Measure the execution time of a single script.
.. code:: bash
ffpy script1.py -s
Output:
.. code:: bash
Execution time: 30.1924 ms
- **Double File (Comparison):** Compare the execution times of two
scripts and determine the percentage difference.
2. Compare the execution times of two scripts:
.. code:: bash
ffpy script1.py script2.py -s
Output:
.. code:: bash
script1.py
Execution time: 29.2735 ms
script2.py
Execution time: 533.9346 ms
script1.py is 1723.95% faster than script2.py
- **More Than Two Files (Detailed Table):** Compare execution times of
multiple scripts and display a detailed table with filenames and
average execution times.
3. Compare execution times of multiple scripts and display a detailed
table:
.. code:: bash
ffpy script1.py script2.py script3.py -s
or
.. code:: bash
ffpy path/to/scripts
Output:
.. code:: bash
script1.py
Execution time: 30.0028 ms
script2.py
Execution time: 533.4799 ms
script3.py
Execution time: 1035.9304 ms
╒════════════╤═══════════════════════════════╕
│ Filename │ Average Execution Time (ms) │
╞════════════╪═══════════════════════════════╡
│ script1.py │ 30.0028 │
├────────────┼───────────────────────────────┤
│ script2.py │ 533.48 │
├────────────┼───────────────────────────────┤
│ script3.py │ 1035.93 │
╘════════════╧═══════════════════════════════╛
How to Use 🤔
~~~~~~~~~~~~~
1. Start by including a simple ``hello.py`` Python script as an example:
.. code:: python
print("Hello, FFpy!")
You can measure its execution time using FFpy:
.. code:: bash
ffpy hello.py
This should yield the following output:
::
Hello, FFpy!
Execution time: XX.XX ms
2. Now, let’s examine the runtime of two different sorting algorithms.
We have a list of 1000 integers, and we’ll use ``merge_sort.py`` and
``bubble_sort.py`` to sort them as examples:
.. code:: bash
ffpy merge_sort.py bubble_sort.py --silent
This will produce the following output:
::
merge_sort.py
Execution time: 33.2839 ms
bubble_sort.py
Execution time: 65.3996 ms
merge_sort.py is 96.49% faster than bubble_sort.py.
This difference in execution time is due to the fact that Merge sort is
faster than bubble sort, thanks to its efficient divide-and-conquer
approach, resulting in a time complexity of O(n log n). On the other
hand, bubble sort, with its quadratic time complexity of O(n^2), proves
to be less efficient for large datasets. We can clearly see the
execution time differences between two programs. `Learn more [2] about
time
complexity. <https://github.com/anxkhn/FFpy/blob/main/learn_more.md#2-learn-more-about-sorting-algorithms-their-time-complexity-and-efficiency>`__
Contributing 🤝
---------------
If you’d like to contribute to FFpy, feel free to fork the repository
and submit a pull request.
License 📜
----------
This project is licensed under the GPLv3 License - check out `this
website <https://www.tldrlegal.com/license/gnu-general-public-license-v3-gpl-3>`__
for more information.
""",
long_description_content_type="text/x-rst",
author="Anas Khan",
author_email="[email protected]",
url="https://github.com/anxkhn/FFpy",
license="GPL-3",
)