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