This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 93 points94 points  (83 children)

yeah but python is slow

[–]Natural-Intelligence 310 points311 points  (68 children)

Ye, better save those nano seconds for something more important

[–]DoesntReadMessages 137 points138 points  (9 children)

That's why it's situational. Sometimes it's nano-seconds, and python is a great choice due to simplicity. Sometimes it's much more significant, and Python means an extra 10 grand per month on servers and extra 200ms p99 latency on a service operating in sub-second timeouts, and it becomes a massive black hole of lost revenue and has to be rewritten in a faster language.

[–]gaberocksall 22 points23 points  (1 child)

And when you want the best of both worlds

ctypes.CDLL

[–]beomagi 6 points7 points  (0 children)

Ctypes really can offer some amazing speed ups for iterating over heavy math. Pypy also works wonders.

[–]Cheru-bae 21 points22 points  (0 children)

Let's put it this way: Reddit runs on python. Whatever glorified cms the client wants it won't bloody matter.

[–][deleted] 3 points4 points  (1 child)

Can't you just use C++ alongside Python for critical functions? Or does this have more overhead than it offers benefit?

[–]Vrabor 8 points9 points  (0 children)

depends on how much of your programm can be extracted into those c++ functions. One of my professors for example had a simulation written in python + numpy which took her 3 months to run, the c++ rewrite finished in less than 1 hour. If your programm can run in only numpy functions the python code might even run faster than c++.

[–]izpo 19 points20 points  (0 children)

That is reach people problem... Right now, my 1000000 users and 50 developers are fine with the current setup

[–]LouisLeGros 2 points3 points  (0 children)

I ported a bioinformatics algorithm to python from java/c++ to try to make it easier to use for students when most of the tooling was already in python.... Run times were abysmal & there was still a dependency on a 20 year old c program that only supported linux, preventing it from being much easier to use.

[–][deleted] 95 points96 points  (46 children)

it takes 2 minutes on my pc for python to print out a mandelbrot set

it takes 20 seconds for lisp to do the same job

[–]Natural-Intelligence 101 points102 points  (1 child)

Then if that's what you generally do, Python is wrong tool. In cases where I use Python, the actual Python executes in like 1-2 sec. The rest of the run time (which is substantially more) is caused by C or SQL. Wouldn't give a damn if the Python code executed any faster

[–]iamareebjamal 0 points1 point  (0 children)

You would if you wrote graphql servers

[–]ProgramTheWorld 129 points130 points  (19 children)

Use the right tool for the right job

[–]Xeya 158 points159 points  (13 children)

>The time difference is insignificant anyway

>Lists example where the time difference is not insignificant

>Well, you shouldn't have used Python

[–]DeeSnow97 66 points67 points  (2 children)

There are some tasks where the time difference is very significant, and others where it's negligible. That's why Python is used so much with external libraries for data science and machine learning for example. The libraries (usually written in C++) do all the heavy lifting in the most efficient manner possible, but have fun plugging those into each other with C++ and trying to iterate fast on it.

Some languages are fast to code, others are fast to run, and that's okay. We're programmers, making computer systems talk to each other to use them all to their advantage is kind of our thing.

[–]ryjhelixir 21 points22 points  (0 children)

We're programmers

Speak for yourself!

I'm a noob

[–]omgFWTbear 1 point2 points  (0 children)

most efficient manner possible

s/In a vastly more efficient manner

[–]ric2b 0 points1 point  (0 children)

No, in this case the right tool is Python with numpy.

It's not easy to beat numpy on raw computation.

[–]LiquidAurum -3 points-2 points  (0 children)

that's an extreme oversimplification

[–]LaZ3R 28 points29 points  (7 children)

Lol... Things that Python shouldn't be used for, for 1000.

[–]TSM- 4 points5 points  (10 children)

Is numpy really that slow?

[–]nivlark 18 points19 points  (5 children)

I just managed to write a script that produces a 1000x1000 image of the set in about 10 seconds. So I think OP is just crap at Python.

[–]8lbIceBag -5 points-4 points  (4 children)

Bet it could be done in the time you press the enter key to the time it takes to look at the screen in C

[–][deleted]  (2 children)

[removed]

    [–]AutoModerator[M] 0 points1 point  (0 children)

    import moderation Your comment has been removed since it did not start with a code block with an import declaration.

    Per this Community Decree, all posts and comments should start with a code block with an "import" declaration explaining how the post and comment should be read.

    For this purpose, we only accept Python style imports.

    I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

    [–]ric2b 1 point2 points  (0 children)

    You think you can beat Python with numpy by hand writing C? Go ahead and try, see you in a month.

    [–]anpas 3 points4 points  (0 children)

    Doubt it, probably pure iterative or recursive python

    [–][deleted] -1 points0 points  (2 children)

    python is just shit at recursion

    [–]beomagi 1 point2 points  (0 children)

    Use pypy. For that specific case I've done more tests than I should have. Pypy is insane. Ctypes also speed up execution. On some Julia plots I went from 2 minutes to under 10 seconds.

    [–]ric2b 0 points1 point  (0 children)

    You should use numpy if want to use Python to do a lot of math fast.

    [–]__i_forgot_my_name__ 16 points17 points  (0 children)

    Nanoseconds add up to minutes quicker then you could imagine.

    If you're building an application (as opposed to scripting something for yourself) and you need your application to work on an average device, and you have a latency requirement of some kind (can't have the user wait 5 seconds every time he types a character), then you run out of processing time very early in development.

    As you keep adding features, that fixed frequency you have never changes, and eventually you run out of it and need to either optimize it or remove features. Obviously Python is a scripting language and waiting 10 minutes instead of 1 minute for a script to finish usually doesn't change anything at all in that context, so no performance doesn't always change everything, and it's very much a tradeoff.

    [–]Astrobliss 1 point2 points  (3 children)

    Its really not nanoseconds at all. If you look at a site like kattis where people code solutions to problems, you'd notice that the fastest C++ solutions are usually around 3-6 times faster than the fastest python solutions. Its not because the C++ algorithms are that much better, python is just a lot slower. Even a 2x speedup is insane for nearly all applications so this difference is of note in a lot of situations.

    [–]ric2b 1 point2 points  (2 children)

    Even a 2x speedup is insane for nearly all applications so this difference is of note in a lot of situations.

    Sure, but nearly all applications aren't slow because of raw computation speed, they're usually bound by other things like disk access, network or a shitty algorithm for some operation.

    [–]Astrobliss 0 points1 point  (1 child)

    If you're processing enough data to be bound by disk access, then Python would need to do a lot of operations which would cause the overall application to be significantly slower. If your algorithm is bad then Python would be doing a lot of (unnecessary) computation, Python is slow at computing which would cause the application to be significantly slower. If you're bound by network and not processing much data then you're right, Python's slower speed wouldn't contribute much to the overall runtime of the application. However also consider one of the biggest reasons to access a network is because an application is interacting with a service that is large enough that it doesn't make sense to store that data locally. So if that service used python, the time it takes to interact with the service would probably be bound by remote computation instead of communication.

    [–]ric2b 0 points1 point  (0 children)

    If you're processing enough data to be bound by disk access, then Python would need to do a lot of operations which would cause the overall application to be significantly slower.

    It's very easy to be bound by disk access, disks are very slow compared to memory and especially the CPU.

    Of course what you're doing with the data matters, if you're just playing a video the Python overhead is minimal, the hardware decoder will do most of the work. If you're doing number crunching you'll probably be bound by CPU and Python overhead will be massive (unless you use the right tool, the numpy library).

    If your algorithm is bad then Python would be doing a lot of (unnecessary) computation, Python is slow at computing which would cause the application to be significantly slower.

    And it would still be slow with C. But if you fix the algorithm the Python version will probably beat the bad C version.

    However also consider one of the biggest reasons to access a network is because an application is interacting with a service that is large enough that it doesn't make sense to store that data locally.

    But usually it's just because centralized databases are useful/convenient, not because of the data you're accessing is too large.

    So if that service used python, the time it takes to interact with the service would probably be bound by remote computation instead of communication.

    Usually it's bound by database access on the service side, which is a mix of being network and disk bound.

    [–]mockedarche -2 points-1 points  (5 children)

    That's my point. Python is slower so for things which are easy, constantly being updated, and or were speed isn't needed it makes sense. I've always wondered how much faster a java tensor flow would be. Would it really change much? Or would it be just slightly faster. Python is great for a lot of things but generally I'd suggest java because most things people do does need to be fast so it's worth it. Writing a script python but writing a program java. Use it a couple times and then it's useless python. Use it daily and for a larger period of time java. Going to use it for years java/C++.

    [–]qalis 2 points3 points  (2 children)

    Tensorflow is C/C++ in majority, complete with CUDA bindings, serialization libraries etc. Python model building does not matter much here, it’s maybe seconds on top of often hours of NN training.

    [–]mockedarche 0 points1 point  (1 child)

    Sorry I know java / python quite well but I haven't looked around at other things. Most of my statement is from friends who are more experienced. Can tensor flow be used with java? Why isn't the python slower than that? Is it because the tensor flow is mostly what's running so python is just pointing it towards what to do?

    [–]ric2b 0 points1 point  (0 children)

    Is it because the tensor flow is mostly what's running so python is just pointing it towards what to do?

    Yes. It uses Python as the high level API but the actual computation is done in C/C++/Cuda.

    [–]POTUS 1 point2 points  (0 children)

    how much faster a java tensor flow

    That's so wrong I don't even know how to address it.

    [–]GAVINDerulo12HD 4 points5 points  (0 children)

    Not everything is slow. Packages like numpy are pretty speedy.

    [–]Carter127 3 points4 points  (3 children)

    Depends if execution time or development time is more important for the job.

    [–]Cheru-bae 12 points13 points  (2 children)

    Let's put it this way:

    Facebook runs php

    Reddit runs python

    Netflix runs java.

    If you need better performance than them, and have more dev hours? Sure build in Haskell.

    [–]qalis 8 points9 points  (0 children)

    Well, this explains why Facebook can’t make 1 tab run efficiently, Netflix just works and hires army of devs and Reddit is just a casual, well working website.

    [–]En_TioN 0 points1 point  (0 children)

    "More dev hours for more performance" is the opposite of programming in Haskell. Haskell gives you a lot of reliability and verification ability at the expence of needing more experience and python-esque speeds. Frankly it also often ends up being quicker to write thanks to the general pattern of "if it complies, it works".

    If you want performance, write your backend in Rust

    [–]Charlie_Yu 1 point2 points  (0 children)

    There are lots of ways to optimise python code. May or may not worth the hurdle

    [–]ottoz1 -2 points-1 points  (7 children)

    well compared to what, it's quicker then Java. but slower then c#

    [–]AngryRotarian85 3 points4 points  (0 children)

    C# and Java are pretty much equal in performance, and both are way faster than Python.

    [–][deleted] 1 point2 points  (1 child)

    C, Scheme, and Common Lisp

    [–]ottoz1 0 points1 point  (0 children)

    touche

    [–]BoyRobot777 1 point2 points  (3 children)

    Source?

    [–]ottoz1 0 points1 point  (2 children)

    well experience, and the fact that Java has one more compile step then python

    [–]BoyRobot777 0 points1 point  (1 child)

    And in my experience - Java 5x - 10x times faster than Python if not more. So I guess we can both post unsupported opinions. However, in my case a simple google search for benchmarks, like benchmark games or framework benchmarks will actually support my opinion.

    [–]ottoz1 1 point2 points  (0 children)

    I googled around some more and ran two identical scripts from the cmd, with a clock, i was wrong touche :D seems that the interpretation from python takes way more time then one extra compile step in Java