7

I couldn't think why people say python is slow.

Comments
  • 12
    Metrics, mostly.
  • 5
    People say Ruby is slow as well.

    Slow compared to C? Absolutely.
    Slow compared to everything similar, including php and python? Not at all.
  • 6
    @Root basically everything is slow compared to C
  • 2
    @10Dev But it doesn't more affect in smaller projects
  • 16
    @10Dev In other news, water is wet and fire is hot.
  • 4
    Word has it that Python is slow, but does it matter to you? Are you running into problems?

    I just spent time tonight trying to check a specific index in arrays thinking it would be quick to check that index rather than the whole array, but due to the wonky nature of some other stuff I'm working on that was harder to do than I realized... and then I just checked all of the array's values ... and threw a ton of arrays at the same code and ... wasn't slow anyway :P
  • 6
    Unless you're trying to solve coding problems with algorithms that are only allowed to run for so long, I wouldn't worry about a language being "slow".
  • 5
    Apparently it's not great for multithreading
  • 8
    Well.
    have to handle 1m calls per second? don't use python.
    have to handle 1 call per minute? use python.
  • 1
    @magicMirror these 1m calls are rarely handled
  • 10
    @devraj45
    More rare for some than others. Every system I've worked on for the last decade has handled at least that.

    Python is a great tool for what it's good for. There's no need to defend its honor as a golden hammer.
  • 11
    Because it's a snake. If you want to go faster you need an animal with legs.
  • 2
    People compare apples to oranges.

    Slower than what? Assembly? Is the speed difference visible for average use case?

    Python's dynamic typing and interpreted nature means that it handles memory very differently than the usual 'fast' languages. Plus I can drop back to C modules if I need speed(like numpy). And there are ways around GIL for better multithreading.
  • 0
    @d4ng3r0u5 there are also flying snakes
  • 1
    It's fast enough for a lot of things, but not most things, and most definitely not whatever one might want to do. Recently I had someone tell me I should use Java because it's fast enough for anything I would want to do. I was doing real-time sound manipulation. So yeah, inefficiency does mean that there are a lot of things you can't do with python.

    Another thing, python, and languages in general are never slow. They're inefficient. Which means that they use more hardware for the same task. Not only is python too slow for 1m calls on whatever you measure it on, it's also too slow for 100calls/s on a raspberry. The target matters.
  • 1
    We started with python in a big data course, and training our decision trees took about 8 hours. It took us 8 hours to make the same tree in c# where it took about 10 minutes to train.
  • 0
    @magicMirror fwiw I can use even Bash to serve 1M calls per second, if my environment ir wide enough and the downstream components can handle the concentrsted load [e.g. DB.

    If I have 1M servers that's 1call/second to serve per server if I want the 1M/s tx rate

    are you saying py can't handle that?
  • 0
    @netikras Can bash even run 1m lines per second?
  • 1
    @devraj45
    You need to plan for 1m/s calls, and prepare for the spikes.
    Requires very strong infra/load balancing and planing/auto scaling/monitoring/CDN space and more.

    for 1 call a minute? probably use you home rpi0.
  • 0
    @Lor-inc Almost

    ```
    netikras@netikras-xps:/tmp/playground$ for i in $(seq 1 1000000) ; do echo 'a=4' ; done >/tmp/playground/1Mloc.bash
    netikras@netikras-xps:/tmp/playground$ vim 1Mloc.bash
    netikras@netikras-xps:/tmp/playground$ time ./1Mloc.bash >/dev/null

    real 0m1,663s
    user 0m1,631s
    sys 0m0,012s
    netikras@netikras-xps:/tmp/playground$
    ```
  • 0
    @Lor-inc After switching to `performance` governor

    ```
    netikras@netikras-xps:/tmp/playground$ time ./1Mloc.bash >/dev/null

    real 0m1,108s
    user 0m1,102s
    sys 0m0,007s
    netikras@netikras-xps:/tmp/playground$
    ```

    close
  • 2
    @netikras Oh. yes of course bash and python can handle 1m calls.

    And on the same idea: if you had enough money for it, even pigeons can do that. just buy enough pigeons to handle the load.
    /s
  • 1
    @magicMirror there's no need for sarcasm. If we're comparing who/what has the longest - let's agree on units and measuring conditions. To have an apples-apples and not oranges-puppies comparison.
  • 0
    @netikras So if you handle each request with a single line (which is perfectly reasonable knowing bash) then it's a million requests/s. That's good to know.
  • 2
    @netikras oranges taste better than puppies
  • 2
    @electrineer but they barely meow
  • 0
    Python is pretty slow compared to some other languages. But depending on the scope of your project as well as its purpose, the benefits might outweigh the drawbacks.

    I write code that interacts with AWS, and Python has the best AWS library by far (or at least better than the alternatives we considered, like Go's AWS SDK). And because the code is interacting with AWS APIs, the API latency accounts for like 95% of the run time. Switching to a faster or multithreaded language would shave off a few milliseconds, but when your run time is measured in seconds, that is hardly a benefit at all.

    Meanwhile, we would have to write twice as much code since the Go AWS SDK is just a thin wrapper around the REST API while Python's boto3 library has a ton of built-in convenience like resource collections.
  • 1
    @netikras don't get me wrong here: it is a question of cost/benefit in the way I look at it.

    how much does it cost to perform 1m server calls in each platform?
  • 0
    @magicMirror depends on so many factors across different platform providers... Mostly on the duration of the execution (e.g. lambda) could depend on the intensity of the transaction processing (EC2 instance type), could also depend on the payload size (in/out), time of the day/day of the week, most likely depends on the downstream calls, etc. Can't give you the numbers. And I really don't know all the platforms and all the ways they can serve a request, not to mention the billing matters.
  • 0
    @magicMirror If you meant to say that having 1M servers is more expensive than X servers, where x<1M, then you'd be correct. But that's not the point I was trying to make :)

    I believe bash could serve 1M requests in a second even if it ran on .7M servers. Perhaps it could serve even if it ran on .5M servers. It's possible it could <repeat with lower number until you or someone else posts the hard numbers what bash is capable of>.

    The same applies to Python or whatever we're comparing -- unless anyone provides actual metrics along with testing conditions' descriptions, we can assume that Python can most likely serve 1M requests in 1 second if it ran on 1M servers. Just like Bash. And Java. And C#. And whatnot.
Add Comment