I compared python3 standard argparse and python-fire

I compared argparse and python-fire of the command line argument management module by the number of codes and processing time.

argparse Just before importing argparse, get the current time and measure the processing time, ʻif name =='main': There is a lot of code in, and say` is repeated 3 times. Not smart.

import time
start = time.time()
import argparse

def say():
    print(f"From the beginning{time.time()-start}Seconds have passed")

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("--say",action="store_true")
    args = parser.parse_args()
    if args.say:
        say()

Execute this Execute with the following command $python3 argparse_test.py --say The output is 0.01373600959777832 seconds have passed since the start Processing speed is fast

python-fire Compared to argparse, the amount of code in ʻif name =='main':` is only one line

import time
start = time.time()
import fire

def say():
    print(f"From the beginning{time.time()-start}Seconds have passed")

if __name__ == '__main__':
    fire.Fire()

Execute with the following command python3 fire_test.py say The output is 0.7563726902008057 seconds have passed since the start It takes about 0.7 seconds to load python-fire, but it's simple

Recommended Posts

I compared python3 standard argparse and python-fire
I compared Java and Python!
I compared Python more-itertools 2.5 → 2.6
I compared "python dictionary type" and "excel function"
I compared blade and jinja2
I compared Qiskit and Blueqat (beginner)
I personally compared Java and Ruby
I played with PyQt5 and Python3
I compared the speed of Hash with Topaz, Ruby and Python
[Introduction to Python] I compared the naming conventions of C # and Python.
I compared Node.js and Python in creating thumbnails using AWS Lambda
Python Paiza-Various skill checks and standard input
Calculate and display standard weight with python
Python3 standard input I tried to summarize
I installed and used Numba with Python3.5
I compared Python's iterator and Ruby's Enumerator
I replaced the numerical calculation of Python with Rust and compared the speed
[Python] I introduced Word2Vec and played with it.
I tried web scraping using python and selenium
I compared the speed of go language web framework echo and python web framework flask
I compared the speed of regular expressions in Ruby, Python, and Perl (2013 version)
I tried object detection using Python and OpenCV
[Python] Standard input
I started python
I wrote a class in Python3 and Java
I tried Jacobian and partial differential with python
I tried function synthesis and curry with python
python argparse template
I / O related summary of python and fortran
I compared the speed of the reference of the python in list and the reference of the dictionary comprehension made from the in list.
Calculation of standard deviation and correlation coefficient in Python
I tried pipenv and asdf for Python version control
I want to handle optimization with python and cplex
Receives and outputs standard output of Python 2 and Python 3> C implementations
This time I learned Python I and II at Progate.
I checked out the versions of Blender and Python
I made a LINE BOT with Python and Heroku
I implemented collaborative filtering (recommendation) with redis and python
Python: I tried a liar and an honest tribe
[python] Compress and decompress
I tried using argparse
Python and numpy tips
[Python] pip and wheel
Batch design and python
Python iterators and generators
Python packages and modules
Vue-Cli and Python integration
I tried Python> autopep8
Ruby, Python and map
python input and output
I implemented Python Logging
Python and Ruby split
Relearn Python (Algorithm I)
[Python] About standard input
Python3, venv and Ansible
I tried Python> decorator
Python asyncio and ContextVar
Why I chose Python
[Python of Hikari-] Chapter 08-03 Module (Import and use of standard library)
I tried [scraping] fashion images and text sentences in Python.
I got an error in vim and zsh in Python 3.7 series