FFpy


NameFFpy JSON
Version 1.6.2 PyPI version JSON
download
home_pagehttps://github.com/anxkhn/FFpy
SummaryFast Python Script Execution Timer
upload_time2023-12-30 15:44:41
maintainer
docs_urlNone
authorAnas Khan
requires_python
licenseGPL-3
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
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.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/anxkhn/FFpy",
    "name": "FFpy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Anas Khan",
    "author_email": "anxkhn28@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/5d/5e/5a379d072ea77ff0ceedee93224ac532e8919fb820c2d8475061f47f9fab/FFpy-1.6.2.tar.gz",
    "platform": null,
    "description": "\r\nFFpy - \u26a1 Fast Python Script Execution Timer\r\n============================================\r\n\r\nFFpy is a command-line tool that measures the execution time of Python\r\nscripts. It provides flexibility by allowing you to specify the time\r\nunit (milliseconds or seconds) and the number of runs for more accurate\r\nmeasurements.\r\n\r\nBackground \ud83d\ude80\r\n-------------\r\n\r\nAs an undergraduate software engineer with Python as my weapon of choice\r\nfor coding, I often found myself curious about the execution time of my\r\nscripts. While solutions like ``timeit`` module exist, I wanted a\r\nseamless way to measure execution time without adding another line of\r\ncode to my programs. This led to the creation of FFpy.\r\n\r\nIn my coding journey, especially while tackling Data Structures and\r\nAlgorithms problems and optimizing code, understanding the execution\r\ntime can provide valuable insights.\r\n\r\nFFpy aims to be a simple yet powerful tool for easily benchmarking\r\nperformance without the need to modify your existing codebase. I believe\r\nin keeping things straightforward. FFpy is designed to be a\r\nminimalistic, no-nonsense module that integrates seamlessly into your\r\nworkflow, allowing you to focus on coding while effortlessly obtaining\r\nexecution time metrics.\r\n\r\nInstallation \ud83d\udee0\ufe0f\r\n---------------\r\n\r\nInstall FFpy using ``pip``:\r\n\r\n.. code:: bash\r\n\r\n   pip install ffpy\r\n\r\nAlternatively, you can clone this repository:\r\n\r\n.. code:: bash\r\n\r\n   git clone https://github.com/anxkhn/FFpy.git\r\n   cd FFpy\r\n   pip install .\r\n\r\nUsage \ud83d\udea8\r\n--------\r\n\r\nAfter installation, you can use FFpy to measure the execution time of\r\nyour Python scripts. Here\u2019s the basic syntax:\r\n\r\n.. code:: bash\r\n\r\n   ffpy <filename.py/folder> <filename2.py> [-u <unit>] [-n <num_runs>] [-s] [-m <mode>] [-v] [-h]\r\n\r\n-  ``<filename.py/folder>``: Replace with the actual filename or folder of your Python script(s) in the current directory.\r\n\r\n-  ``<filename2.py>``: Optional second script for comparison.\r\n\r\n-  ``-u, --unit``: Optional flag to specify the time unit (ms or s,\r\n   default is ms).\r\n\r\n-  ``-n, --number``: Optional flag to specify the number of runs\r\n   (default is 1).\r\n\r\n-  ``-s, --silent``: Optional flag to run the script silently (suppress\r\n   output).\r\n\r\n-  ``-m, --mode``: Optional flag to specify the threads (single or\r\n   multi, default is single).\r\n\r\n-  ``-v, --version``: Display script version.\r\n\r\n-  ``-h, --help``: Display help message.\r\n\r\nExamples \ud83c\udf08\r\n~~~~~~~~~~~\r\n\r\n1. Measure the execution time of a script in milliseconds:\r\n\r\n.. code:: bash\r\n\r\n   ffpy script.py\r\n\r\n2. Measure the execution time in seconds:\r\n\r\n.. code:: bash\r\n\r\n   ffpy script.py -u s\r\n\r\n3. Run the script 10 times and measure the average execution time:\r\n\r\n.. code:: bash\r\n\r\n   ffpy script.py -n 10\r\n\r\n4. Run the script silently:\r\n\r\n.. code:: bash\r\n\r\n   ffpy script.py -s\r\n\r\n5. Run scripts concurrently using multithreading mode:\r\n\r\n.. code:: bash\r\n\r\n   ffpy script.py -m multi\r\n\r\n**Note on Multithreading Mode:**\r\n\r\nWhen using the multithreading mode (``-m multi``), the script will be\r\nexecuted concurrently in a multithreaded fashion, leveraging multiple\r\ncores on your system. It\u2019s important to note that the average execution\r\ntime in multithreading mode may not be equal to running the program\r\nonce, as multithreading introduces parallelism and can lead to\r\nvariations in execution times. `Learn more [1] about\r\nmultithreading. <https://github.com/anxkhn/FFpy/blob/main/learn_more.md#1-learn-more-about-multithreading-and-how-it-works>`__\r\n\r\nTypes of Operation:\r\n-------------------\r\n\r\n-  **Single File:** Measure the execution time of a single script.\r\n\r\n.. code:: bash\r\n\r\n   ffpy script1.py -s\r\n\r\nOutput:\r\n\r\n.. code:: bash\r\n\r\n   Execution time: 30.1924 ms\r\n\r\n-  **Double File (Comparison):** Compare the execution times of two\r\n   scripts and determine the percentage difference.\r\n\r\n2. Compare the execution times of two scripts:\r\n\r\n.. code:: bash\r\n\r\n   ffpy script1.py script2.py -s\r\n\r\nOutput:\r\n\r\n.. code:: bash\r\n\r\n   script1.py\r\n   Execution time: 29.2735 ms\r\n   script2.py\r\n   Execution time: 533.9346 ms\r\n   script1.py is 1723.95% faster than script2.py\r\n\r\n-  **More Than Two Files (Detailed Table):** Compare execution times of\r\n   multiple scripts and display a detailed table with filenames and\r\n   average execution times.\r\n\r\n3. Compare execution times of multiple scripts and display a detailed\r\n   table:\r\n\r\n.. code:: bash\r\n\r\n   ffpy script1.py script2.py script3.py -s\r\n\r\nor\r\n\r\n.. code:: bash\r\n\r\n   ffpy path/to/scripts\r\n\r\nOutput:\r\n\r\n.. code:: bash\r\n\r\n   script1.py\r\n   Execution time: 30.0028 ms\r\n   script2.py\r\n   Execution time: 533.4799 ms\r\n   script3.py\r\n   Execution time: 1035.9304 ms\r\n   \u2552\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2564\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2555\r\n   \u2502 Filename   \u2502   Average Execution Time (ms) \u2502\r\n   \u255e\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u256a\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2561\r\n   \u2502 script1.py \u2502                       30.0028 \u2502\r\n   \u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\r\n   \u2502 script2.py \u2502                      533.48   \u2502\r\n   \u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\r\n   \u2502 script3.py \u2502                     1035.93   \u2502\r\n   \u2558\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2567\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255b\r\n\r\nHow to Use \ud83e\udd14\r\n~~~~~~~~~~~~~\r\n\r\n1. Start by including a simple ``hello.py`` Python script as an example:\r\n\r\n.. code:: python\r\n\r\n   print(\"Hello, FFpy!\")\r\n\r\nYou can measure its execution time using FFpy:\r\n\r\n.. code:: bash\r\n\r\n   ffpy hello.py\r\n\r\nThis should yield the following output:\r\n\r\n::\r\n\r\n   Hello, FFpy!\r\n   Execution time: XX.XX ms\r\n\r\n2. Now, let\u2019s examine the runtime of two different sorting algorithms.\r\n   We have a list of 1000 integers, and we\u2019ll use ``merge_sort.py`` and\r\n   ``bubble_sort.py`` to sort them as examples:\r\n\r\n.. code:: bash\r\n\r\n   ffpy merge_sort.py bubble_sort.py --silent\r\n\r\nThis will produce the following output:\r\n\r\n::\r\n\r\n   merge_sort.py\r\n   Execution time: 33.2839 ms\r\n   bubble_sort.py\r\n   Execution time: 65.3996 ms\r\n   merge_sort.py is 96.49% faster than bubble_sort.py.\r\n\r\nThis difference in execution time is due to the fact that Merge sort is\r\nfaster than bubble sort, thanks to its efficient divide-and-conquer\r\napproach, resulting in a time complexity of O(n log n). On the other\r\nhand, bubble sort, with its quadratic time complexity of O(n^2), proves\r\nto be less efficient for large datasets. We can clearly see the\r\nexecution time differences between two programs. `Learn more [2] about\r\ntime\r\ncomplexity. <https://github.com/anxkhn/FFpy/blob/main/learn_more.md#2-learn-more-about-sorting-algorithms-their-time-complexity-and-efficiency>`__\r\n\r\nContributing \ud83e\udd1d\r\n---------------\r\n\r\nIf you\u2019d like to contribute to FFpy, feel free to fork the repository\r\nand submit a pull request.\r\n\r\nLicense \ud83d\udcdc\r\n----------\r\n\r\nThis project is licensed under the GPLv3 License - check out `this\r\nwebsite <https://www.tldrlegal.com/license/gnu-general-public-license-v3-gpl-3>`__\r\nfor more information.\r\n\r\n",
    "bugtrack_url": null,
    "license": "GPL-3",
    "summary": "Fast Python Script Execution Timer",
    "version": "1.6.2",
    "project_urls": {
        "Homepage": "https://github.com/anxkhn/FFpy"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9d1fcd20418ed40afca0dac139f11eb0dcf385b834234aa1e04abf21efadcd9f",
                "md5": "ca06eb00a7d285956307c7262bfbc6c4",
                "sha256": "e48c2ca4a9aa09d1d5551d437bbfde97e10e51b7f99ae97e11cf9fd47334f949"
            },
            "downloads": -1,
            "filename": "FFpy-1.6.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ca06eb00a7d285956307c7262bfbc6c4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 7608,
            "upload_time": "2023-12-30T15:44:39",
            "upload_time_iso_8601": "2023-12-30T15:44:39.540674Z",
            "url": "https://files.pythonhosted.org/packages/9d/1f/cd20418ed40afca0dac139f11eb0dcf385b834234aa1e04abf21efadcd9f/FFpy-1.6.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5d5e5a379d072ea77ff0ceedee93224ac532e8919fb820c2d8475061f47f9fab",
                "md5": "deaaf2f9bfb0ded0db50fbb20d79b179",
                "sha256": "a88e150b4d697618d3ddc2e414ff45b4c9ea3f26396bae59019f5650346f7e4c"
            },
            "downloads": -1,
            "filename": "FFpy-1.6.2.tar.gz",
            "has_sig": false,
            "md5_digest": "deaaf2f9bfb0ded0db50fbb20d79b179",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6338,
            "upload_time": "2023-12-30T15:44:41",
            "upload_time_iso_8601": "2023-12-30T15:44:41.402118Z",
            "url": "https://files.pythonhosted.org/packages/5d/5e/5a379d072ea77ff0ceedee93224ac532e8919fb820c2d8475061f47f9fab/FFpy-1.6.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-30 15:44:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "anxkhn",
    "github_project": "FFpy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "ffpy"
}
        
Elapsed time: 0.52025s