4 ms·
I just tried on an app at work (Django app): > time python manage.py --help real 0m0.473s user 0m0.240s sys 0m0.148s Half of a second is very
by thu 12y ago
I just tried on an app at work (Django app):
> time python manage.py --help
real 0m0.473s
user 0m0.240s
sys 0m0.148s
Half of a second is very noticeable (and annoying). I had similar perception in my previous work.
You can try to only load enough to display the help text without really loading everything, but that doesn't work that well (you have to organize things differently, and `--help` requires to load a lot of stuff. `subcommand --help` needs less but it still has to see if the subcommand exists).
As a reference:
> time python -c 'print "hello"'
hello
real 0m0.041s
user 0m0.024s
sys 0m0.012s
> time echo hello
hello
real 0m0.000s
user 0m0.000s
sys 0m0.000s
Actually even the first (0.041s) is not instant, while the second one does (I mean as I perceive it visually).
- Touche 12y agoThis is why I use Lua for command-line tools. Here's one such program that makes no attempt to organize code to make --help load faster: real 0m0.006s user 0m0.000s sys 0m0.004s
- witten 12y agoStill, your second example is an order of magnitude faster than the example with Django. That's likely because Django loads the world on startup, parses all your model files, checks your database settings, etc.
- the_mitsuhiko 12y agoTo be fair, Python without loading site packages is pretty damn fast. Definitely faster than most other things loading up. $ time python -S -c 'print "Hello World!"' ... real 0m0.007s user 0m0.004s sys 0m0.003s That's about the same speed it takes my system's cp command to show me an error page: $ time cp -fail ... real 0m0.005s user 0m0.003s sys 0m0.002s
- pekk 12y agoThat is your Django app, not Python itself, putting in that overhead.
- e12e 12y agoCalling a shell built-in isn't really fair -- you should at least compare to /bin/echo (on my system the relevant times are [edit: 0.001s] for echo, 0.007+0.004=0.011 for python -S -c "print 'hello'". Without dropping site-packages (without the -S) python jumps to 0.014+0.012=0.026 -- marginally above 200 ms which I suppose is a perceptible difference between instant, and not-quite-instant). Sadly, both pypy and python3 are slower than python2.7. Also worth nothing that the sys time fluctates for me -- in other words when it is > 0.00s it doesn't appear to have anything to do with the command run.
- masklinn 12y ago> Half of a second is very noticeable (and annoying). I had similar perception in my previous work. That's because it has to load django and the whole django project. Here's click: > time python test.py --help Usage: test.py [OPTIONS] Options: --help Show this message and exit. python test.py --help 0.06s user 0.02s system 95% cpu 0.078 total and argparse: > time python test.py --help usage: test.py [-h] optional arguments: -h, --help show this help message and exit python test.py --help 0.03s user 0.02s system 93% cpu 0.054 total reference: > time python -c 'print "hello"' hello python -c 'print "hello"' 0.01s user 0.01s system 88% cpu 0.025 total