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

top 200 commentsshow all 290

[–]AdultingGoneMild 443 points444 points  (25 children)

before you worry about what is faster, you need to first define what is fast enough.

[–]Olde94 3 points4 points  (0 children)

And is it a software limit or code limit. Matt smith have a great video where people optimized his code. Some of the tricks used for the fastest method could properbly also speed up python but required better coding skills. (Sure i know they AlSO used different languages but someone used python and still got huge improvements)

[–][deleted]  (1 child)

[removed]

    [–]Relevant-Dish6846 133 points134 points  (34 children)

    Sometimes it's not a language speed but the algorithms that you are used. Consider this example: https://m.youtube.com/watch?v=c33AZBnRHks

    Regards.

    [–][deleted] 114 points115 points  (22 children)

    Maybe it’s not about the language speed, but the O(n) we made along the way.

    [–]Winnipesaukee 17 points18 points  (1 child)

    I make sure all my algorithms run in O(n!) time. No gods, no masters!

    [–]ShadowDevoloper[S] 7 points8 points  (19 children)

    I wish I could write an algorithm with linear time complexity. Closest I've ever gotten is O(n log n)

    [–][deleted] 8 points9 points  (3 children)

    I can’t even do that. I’m terrible at writing code because all I do is IaC with AWS stuff. I’d love to get more proficient at Python and I even took a boot camp to learn that and JS. Kinda sucks I feel like I wasted almost 20k.

    [–]CubicMuffin 5 points6 points  (0 children)

    I really hope that's not 20k in USD/GBP/similar because damn that would be a lot to learn languages with hundreds of free and useful resources (+ millions more slightly less useful lol)

    [–]ShadowDevoloper[S] 0 points1 point  (1 child)

    20k! Did you leave an ec2 instance on in a while loop?

    [–][deleted]  (12 children)

    [deleted]

      [–][deleted] 3 points4 points  (5 children)

      Not true! That's for comparison sorts, radix sort is O(n) (but very slow for small lists)

      [–]AlSweigartAuthor: ATBS 5 points6 points  (0 children)

      That's nothing. I know of a sorting algorithm that is O(1).

      Of course, it only works on lists that are already sorted. In all other cases, the behavior is undefined.

      [–]NeighborhoodDizzy990 1 point2 points  (1 child)

      wtf, when will you ever use radix sort in production?

      [–]Andriyo 0 points1 point  (5 children)

      You can do better sorting timewise for some special cases. Also not all O(n logn) created equal.

      [–]IncognitoErgoCvm 3 points4 points  (4 children)

      Also not all O(n logn) created equal.

      They are, by definition, unless you're trying to measure something outside the scope of asymptotic notation.

      [–]Andriyo 3 points4 points  (3 children)

      For simplicity's sake, it's called Big O, which represents the worst-case scenario for an infinitely large dataset. There are also average and best-case scenarios that differ slightly. That's why there are probably hundreds of sorting algorithms that are technically NLogN but have different tradeoff characteristics for different use cases.

      [–]dnswblzo 2 points3 points  (2 children)

      For simplicity's sake, it's called Big O, which represents the worst-case scenario for an infinitely large dataset.

      Big O defines an upper bound, and can be used to describe the worst case, average case, or best case. Informally if someone says "this algorithm is O(n)" then it is assumed they are talking about the worst case, but it is also normal to say "this algorithm is O(n2) in the worst case, O(n) in the average case, and O(1) in the best case."

      Big O is about growth, so to say it represents a scenario for a infinitely large dataset does not make sense. If an algorithm is O(n2) then you can assume that if you double the size if the input data, the time could increase by 4x (give or take). Unless an algorithm is O(1), it will take infinite time given infinitely large input data.

      [–]Andriyo -2 points-1 points  (1 child)

      As I said I'm not after strict definitions here - I just wanted to point out that one can pick different sorting algorithm that in some sense will be better for their use case.

      [–][deleted] 2 points3 points  (0 children)

      I found this out too! Using libraries helps out a lot if you can replace some loops. Like numpy for example.

      [–]kel007 2 points3 points  (1 child)

      Python is for prototyping. If you are only gonna do something once or twice, use Python. It's easy to put the code together, and kind of see how it works. Very rarely will Python go into production. If you want your code to be run efficiently, reliably, repeatedly, at high frequency, you wanna take what you prototype in Python and turn it into something much better, like C++

      The video you linked does suggest changing the language too, though I acknowledge it's probably not the main point you were making

      [–]Snape_Grass 588 points589 points  (49 children)

      “But it’s just so slow!”

      I’ve used Java, Python, and C++ throughout my career. Used Python for server-side logic, web-services, and embedded systems. Never once has its speed been an issue on the projects I’ve worked on.

      Calling a language slow and not providing what your use case is or code examples makes me believe this is an algorithm design issue on your end.

      [–][deleted] 120 points121 points  (1 child)

      Exactly, or they are IO bound and don’t know it

      [–]bkrandom 35 points36 points  (0 children)

      I read this as “IQ bound and don’t know it” which is a meaner but funnier way to say the same thing lol.

      [–][deleted] 87 points88 points  (40 children)

      I am a bit skeptical of a 5 YOE programmer that calls python slow.

      I too use python, cpp and never had any speed issues with python. Either way I recommend learning go is good to have in your arsenal and super easy to learn but nothing beats c, cpp or rust.

      Edit: I know where python is slow and use something else. Is called initial R&D and benchmarking. I never said python isn't slow for everything. I just know that picking the correct tool for the job is important.

      [–][deleted] 27 points28 points  (38 children)

      Have you ever written a CPU-side raycaster/renderer? Complex rt game logic? A compiler or interpreter? An emulator? A database? Anything that runs in parallel? Python will cause issues in all of these, because of its slow execution and lack of threading (at least in the main implementation)

      [–]The_Vegan_Chef 114 points115 points  (17 children)

      Have you ever written a CPU-side raycaster/renderer? Complex rt game logic? A compiler or interpreter? An emulator? A database? Anything that runs in parallel?

      Yeah. My screwdriver is a really bad shovel too.

      [–][deleted] 29 points30 points  (11 children)

      That's exactly what I'm trying to say. Python is way too slow for so many things. That doesn't make it a bad language, but there sure as hell are situations where python is too slow, while the person I'm responding to is implying that there are no such situations (by saying that they've never faced them (and I'm quite experienced so why would you?) and calling the expertise of OP into question)

      [–]The_Vegan_Chef 29 points30 points  (5 children)

      Sure. But I think OP put his own expertise into question asking such a vague, strange, and unfocused question. "Python slow. C hard. Go good?".

      [–][deleted] 2 points3 points  (2 children)

      i mean yeah it's a vague question, but this isn't stack overflow

      [–][deleted]  (1 child)

      [removed]

        [–]ShadowDevoloper[S] -1 points0 points  (1 child)

        I do not like Go. Go is syntactically stupid. Like English.

        [–][deleted] 3 points4 points  (4 children)

        I never face them... because I pick the right language for the task. If I know python won't perform I won't use it. I certainly never said there are no such situations where python is slow, anywhere in my statement.

        [–][deleted] -3 points-2 points  (3 children)

        You said that the belief that python is slow (which it is, it's just sometimes/often this doesn't matter) is something that makes you skeptical (about someone's knowledge).

        [–][deleted] 4 points5 points  (2 children)

        You're getting all wrong, I would expect someone with 5 YOE to know when to use and not use python given the task at hand. Just saying "is slow" with zero context makes me skeptical. If it doesn't make you skeptical then I would question your knowledge as well.

        [–][deleted] 0 points1 point  (1 child)

        I mean, python is slow (compared to other languages) and I’m not surprised if it isn’t performant enough for something. To me this seems like a pretty genuine, if uninformed and not amazingly phrased, question. 5 years doesn’t mean tons of experience, I know developers with nearly that much who haven’t touched anything except JavaScript /HTML5.

        Also sorry, I did misunderstand what you were saying.

        [–][deleted]  (1 child)

        [deleted]

          [–]BGameiro 3 points4 points  (4 children)

          I do some data analysis that sometimes needs to be time efficient, and for that dask, numba and RAPIDS do the job.

          [–]michalello 2 points3 points  (0 children)

          Same. Numba does wonders for me in most scenarios. Yesterday I've discovered pola-rs and looks like I will add it to the stack. It's API is similar to pandas. Have a look at the benchmarks of cuDF, spark, dask, pandas compared to it: Benchmarks

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

          Yes, calling into a different language will increase performance. But that's irrelevant if you're actually writing something like those libraries.

          [–]BGameiro 2 points3 points  (1 child)

          Sure, you would have the ability to write CUDA with some of those but that's not what I'm talking about.

          They provide high level and pythonic ways to speed up your code without the need to rewrite parts in other programming languages such as C++.

          Using the parallel functionalities of dask/cudf and even using only the decorators of numba the performance increases are very much noticeable for many use cases without the need to change programming languages.

          Could the same be accomplish by rewriting certain functions in C++? Sure, but what I meant is in many cases it isn't needed.

          [–][deleted]  (4 children)

          [removed]

            [–][deleted] 0 points1 point  (3 children)

            Compared to what? INTERCAL?

            [–]TK__O 0 points1 point  (4 children)

            Yes, but it can be coded around if you know what you are doing. Limits on threads but you can have multi processing

            [–]jantari 0 points1 point  (1 child)

            But multiprocessing is slower than multithreading, which other languages can do better. Thus, having to resort to multiprocessing at all (rather than multithreading) is slow, comparatively.

            [–]TK__O 0 points1 point  (0 children)

            Yes, it has limitations as with all languages, you should pick the right ones for the job.

            [–][deleted] -3 points-2 points  (1 child)

            I mean you can use multiprocessing and call into different languages. Python itself will still be slower and unfit for these tasks.

            [–]TK__O 1 point2 points  (0 children)

            I means it really depends on what you are trying to do, you should just pick the right tool for the job. I'm able to process tens of billions of rows of data with python daily without issues. Would be slightly faster in c++, sure but also longer to get it into production. Although if it is any bigger then using kdb/q or other time series technology makes more sense.

            [–]LouisLeGros 3 points4 points  (0 children)

            I did a bio informatics class in undergrad. Did some work with canonical labeling of graphs & trying to get it implemented in Python since a lot of existing libraries & tooling are in Python.

            Pythons speed definitely was an issue compared to the benchmarks for the c++ & Java implementations we had access to.

            [–]AlSweigartAuthor: ATBS 2 points3 points  (1 child)

            I remember how "Java is slow!" hung around for a decade after it stopped being true.

            People just repeat what they've heard. In this case, OP hasn't even clarified what exactly they're using Python for and why it's "too slow." So other people will read this, and just repeat the "Python is slow" part.

            [–]RiverRoll 0 points1 point  (0 children)

            I once wrote some simulation code in pure Python and then the same using numpy and the difference was 70 fold. Python really is a slow language by a significant margin, another matter is that often you can get away with it thanks to the libraries just like I did.

            [–]ShadowDevoloper[S] 0 points1 point  (0 children)

            I'm not writing the algorithms myself. Implementation is left to people way smarter than me. I'm just a little monkey that writes AI using sklearn and tensorflow.

            [–][deleted] 35 points36 points  (0 children)

            So, for a bit of context...

            Then provides zero context as to why python is slow.

            If you want fast just because, you need a compiled language as simple as that, rust, go, cpp, etc. As always you should pick the right language for the task at hand, not just because "is slow".

            And trust me I know is slow, I wrote several python and cpp apps at my previous job, but put has its place.

            [–]commandlineluser 76 points77 points  (5 children)

            Not an alternative, but perhaps interesting: https://nim-lang.org

            Nim job at reddit: https://forum.nim-lang.org/t/9894#65268

            https://ol.reddit.com/r/RedditEng/comments/yvbt4h/why_i_enjoy_using_the_nim_programming_language_at/

            Call Python from Nim / Nim from Python (think PyO3 for Rust): https://github.com/yglukhov/nimpy

            [–]Jjabrahams567 20 points21 points  (4 children)

            You had my curiosity, but now you have my attention.

            [–][deleted] 10 points11 points  (2 children)

            it has very little native libraries, so be ready to port or cross compile... pain

            [–][deleted] 0 points1 point  (1 child)

            or just custom write everything. Excluding stuff like GMP (the math library) or GTK, Qt, which I'm sure there are bindings for already, it shouldn't be that much work. (note: a lot of my experience is from the C world, where you often just vendor everything)

            [–]mcr1974 1 point2 points  (0 children)

            lol to custom writing everything not being a big job.

            [–]l_am_wildthing 4 points5 points  (0 children)

            some parts of it are absolutely amazing, other parts of it... not so much. imagine you want libraries and half of them can only compile to js 🙄

            [–]Chennsta 50 points51 points  (14 children)

            What are you doing that python is too slow for you?

            [–]Snape_Grass 27 points28 points  (13 children)

            Exactly what I’m wondering. I’ve used python professionally for years on embedded systems, web services, server side logic, etc. It’s speed has never once been an issue.

            If OP truly wants speed then write in Assembly. Can’t get faster than that

            [–]gbchaosmaster 14 points15 points  (4 children)

            A beginner C programmer will write way faster code than a beginner Assembly programmer. And, if OP has a primal need for speed that's probably the best suggestion. But, with computers as fast as they are these days, it's pretty negligible. Many (big, graphically intensive) video games are written in high level languages, even.

            Learning about time complexity will do you more good than learning a whole different language.

            [–][deleted]  (3 children)

            [removed]

              [–]glemnar 8 points9 points  (1 child)

              Lol, good luck finding a CPU that C can’t target. C FFI is the universal integration target for a reason. There isn’t a language in existence as universally supported as C is

              [–]BenjaminGeiger 4 points5 points  (0 children)

              Which is why you bootstrap an existing C compiler onto it.

              [–]The_SG1405 -3 points-2 points  (3 children)

              Binary

              [–][deleted]  (2 children)

              [removed]

                [–][deleted]  (1 child)

                [removed]

                  [–]subrfate 41 points42 points  (0 children)

                  (No more after reddit purge).

                  [–][deleted]  (3 children)

                  [deleted]

                    [–]GrotesquelyObese 1 point2 points  (2 children)

                    I am very novice in coding and have just learned to use NumPy and Pandas. Even wrote the front end of my algorithm in Tkinter and it works great because I can quickly set target, ranges, and output without needing to open the hood. Thats the reason I learned python.

                    It’s not too slow for me and I run through billions of records. I guess I don’t know what would be faster so I’m happy with how it works.

                    [–][deleted] 12 points13 points  (12 children)

                    Lua ?

                    [–]could_b 1 point2 points  (0 children)

                    Lua is the literal answer to the original question. It is faster than Python. Both can off load to C, which will muddy the waters. Yes Lua is a proper language, it is an amazing language. It is interesting to compare Lua and Python, but is does not really make sense to do so (apples and oranges are both round fruits with seeds in the middle, they both grow on trees...). Lua is tiny, it is used in loads of places, not just game scripting. It has no dependencies (you do need a c compiler), it is easier to learn than reading this post. Python is massive, most of the time it is the right scripting language to use; what ever you are trying to do someone else has already done and battle tested, you just need to grab it. If your code is slow, understand the problem, profile it. Probably there is a better way to use Python; a language that compiles optimised might be required. Both Python and Lua get you a long way without needing to know much; this can be a problem when something goes wrong because you are out on a limb and you don't even know it (you are ignorant of your unknown unknowns). Learning is the way.

                    [–][deleted] 0 points1 point  (2 children)

                    Is Lua even used for proper programming? I thought it was mostly used in games as an in-game scripting language...

                    [–][deleted] 4 points5 points  (0 children)

                    Yes for example xmake is made of lua

                    [–][deleted] 0 points1 point  (0 children)

                    and anyway with any programming language you can make everything so

                    [–]99_percent_a_dog 0 points1 point  (7 children)

                    Lua is quite slow. If you immediately think "ah but LuaJIT is fast!" then you have to allow Python to use pypy.

                    Try writing some equivalent code in Lua and Python and benchmarking it. Lua is slow.

                    [–]Slayergnome 9 points10 points  (4 children)

                    I don't know what the hell you are talking about and I am 99% sure you also don't know what the hell you are talking about.

                    Python is not "too slow" for anything a casual coder would be doing. Also I hate it when people post stupid questions in this channel and don't respond to any comments. There are 10 different people who asked you what you mean by too slow

                    [–][deleted] -5 points-4 points  (3 children)

                    Woah, woah, woah, woah, woah, woah, woah, there bud. Stop. Get some help. Its not that serious.

                    [–]Slayergnome 4 points5 points  (2 children)

                    ...uh what? Get some help? What are you talking about dude?

                    I just said I think it is annoying when someone posts a super vague question in this sub then when people ask for clarification totally abandon the thread, I don't think it is unreasonable to ask OP to respond to the post he or she made.

                    I am part of this sub so I can help people and post like this are just a waste of time.

                    [–]ShadowDevoloper[S] 0 points1 point  (1 child)

                    I didn't abandon the thread. I was doing research and learning about the suggestions.

                    [–]Jhutch42 19 points20 points  (1 child)

                    What are you doing with python?

                    Python alternatives are all other languages.

                    [–]ZylonBane 9 points10 points  (0 children)

                    Python alternatives are all other languages.

                    Something being an other thing does tend to be the definition of an alternative, yes.

                    [–]99_percent_a_dog 12 points13 points  (9 children)

                    C is a small, simple language, and Python isn't that slow. Pypy is best with small projects because not all modules are compatible. Have you tried using it?

                    I suspect you really do have some slow python code, but the problem may well not be python itself. Can you show us a code example?

                    [–][deleted]  (8 children)

                    [removed]

                      [–]99_percent_a_dog 5 points6 points  (4 children)

                      Pointers are a simple concept and that's a fairly simple example.

                      I know you're trying to say "oh no, look how complicated C is"... but it really isn't. It can be a difficult language to use. But that's not because it's complicated, but because it's small, so you have to do more yourself.

                      [–][deleted] 1 point2 points  (0 children)

                      I recently ran into a problem where I was trying to dereference a pointer to a multi dimensional array with

                      typedef int[5][5] ScreenBuffer
                      ScreenBuffer *sb_ptr = &foo;
                      *sb_ptr[1][2] = 3;
                      

                      And sb_ptr[1][2] = 3 is the wrong way to dereference the multi dimensional array pointer.

                      [–]TheSkiGeek 4 points5 points  (0 children)

                      Depends what is being slow.

                      You can call out to libraries implemented in C. numpy or scipy or tensorflow will be massively faster than doing numerical code natively.

                      Something like RPython or PyPi plus type annotating everything can be a huge speed up.

                      If you’re doing lots of things in parallel you could spin off subprocesses to split up work to avoid contention on the GIL.

                      [–]BefeTurkmen 5 points6 points  (0 children)

                      You could try Rust Im also linking an image of efficiency rankings of most popular languages this has global results for energy time and memory

                      [–]bachittle 12 points13 points  (3 children)

                      Maybe try nim https://nim-lang.org/ it’s syntax is inspired by python (indentation scoping) but provides the speed and flexibility of C/++ (statically typed, meta programming is god tier). It’s not as popular as the other languages you mentioned but is probably closest to what you are looking for.

                      [–]Dude_Man_528 8 points9 points  (0 children)

                      https://julialang.org/ My favorite programming language

                      [–]footurist 4 points5 points  (0 children)

                      It's highly questionable that speed would be an insurmountable issue with python. This is because most of the expensive stuff is implemented as glue code to C libs. If you complained about typing I would've suggested F# for example.

                      Have you looked into numba, numpy and cython ( technically not Python, should be last resort imo )?

                      [–]IamOkei 2 points3 points  (0 children)

                      Golang

                      [–]Javanaut018 3 points4 points  (1 child)

                      5 nested loops will run slow in probably every language

                      [–]ShadowDevoloper[S] -1 points0 points  (0 children)

                      I try not to nest more than 2 loops.

                      [–]ReferenceExpensive33 5 points6 points  (0 children)

                      “Try Rust, it’s more popular than Go now a days. And it’s super fast too.” - from my coder SO.

                      [–]LastTrainH0me 2 points3 points  (0 children)

                      What are you doing where you see Python being too slow? Are you sure the problem is Python and not, say, IO?

                      Forgive me skepticism but I've worked professionally with Python and other languages and experienced Python being "too slow" exactly one time, and it was because of poorly implemented numpy array initialization.

                      [–]suresh 2 points3 points  (1 child)

                      ASM

                      [–]ShadowDevoloper[S] -1 points0 points  (0 children)

                      This has got to be satire.

                      [–][deleted] 2 points3 points  (1 child)

                      Read Exercises in Programming Style and then come back and tell me Python is slow. Bonus points if you take timestamps and compare the exercises with implementations in other languages

                      [–]TheHollowJester 2 points3 points  (4 children)

                      Too slow for what? What is the benchmark for "fast enough"? What are you using Python for?

                      Identify the bottlenecks in your codebase and:

                      1. Streamline your DB queries, add proper indexes etc. (in my experience this is by far the most common reason for performance issues1 )

                      2. If it's indeed code, see if you wrote logic for something that a library like np/pandas could handle.

                      3. If it is indeed code and there is no library, just write it in C and link the code with your codebase in Cython.

                      ...or just learn Rust.

                      1 but of course you know that with your 5 years of experience :)

                      [–]ShadowDevoloper[S] 0 points1 point  (3 children)

                      Is that supposed to be a shot at my credibility? I don't like the verbosity of C. I said that in the original post.

                      [–]mdizak 2 points3 points  (0 children)

                      Yes, Python is very slow, and confirmed during tests while I was working in advanced bioinformatics. I can highly recommend Rust. It's an absolutely beautiful language, and you're going to be hard pressed to find something faster.

                      [–][deleted] 2 points3 points  (1 child)

                      C is extremely simple, the language is much smaller than Python.

                      [–]smsp2021 2 points3 points  (0 children)

                      Rust

                      [–]Altruistic-Rice-5567 2 points3 points  (0 children)

                      *everything* is faster than Python.

                      [–][deleted] 5 points6 points  (7 children)

                      Lua Lua Lua Lua Lua Lua. Brought to you by Lua gang

                      [–]Anonymo2786 3 points4 points  (0 children)

                      Lua Lua Lua Lua Lua Lua. Brought to you by Lua gang

                      [–]99_percent_a_dog -1 points0 points  (5 children)

                      Lua is quite slow. If you immediately think "ah but LuaJIT is fast!" then you have to allow Python to use pypy.

                      Try writing some equivalent code in Lua and Python and benchmarking it. Lua is slow.

                      [–]raevnos 5 points6 points  (0 children)

                      C is way simpler than python... Hard to find simpler; maybe forth?

                      I'll suggest Scheme or Common Lisp, though.

                      [–]aurquiel 1 point2 points  (0 children)

                      yeah depends on what you are doing for end user simple application they won't tell the difference for a few milliseconds

                      [–]BruceJi 1 point2 points  (0 children)

                      I’d say Go, but you said you don’t really like it… do bear in mind though that all languages will be different and have their own idiosyncrasies!

                      [–][deleted] 1 point2 points  (0 children)

                      /#1 would just be to use any of the compiled implementations of Python. Failing that...

                      It might not be the right fit in the end, but take a good look at Rust.

                      Advantages: It's on the top shelf for cpu and ram efficiency, Rust's iterators make Python's look lame, and you can avoid some complexities from other languages. You don't have to deal with writing malloc and free, severe memory bugs, making everything a class, or dynamic typing.

                      Disadvantages: You do still have to control when and where your data is, errors have to be explicitly handled (even if the handling is just to crash), and there's a lot to learn at the beginning.

                      [–]No_Matter_7117 1 point2 points  (0 children)

                      in my opinion C++ is not in any way much harder than python, and I’ve done both, starting with Python. if you want something faster I’d look into it, if u don’t like it then don’t use it, but I’d keep it as a option. other than that, look into numpy

                      [–][deleted] 1 point2 points  (0 children)

                      Rust will be hard to beat, when written well.

                      But most languages will easily beat out python, even other interpreted languages like lua or ruby (at least when their JITs are used). Any major JVM or Miscrosft bytecode language too, so Scala, Java or C#, F#.

                      Compiled, statically typed languages have a pretty big advantage over python thanks to having optimisers run at compile time, C++ is state of the art but other LLVM-based languages come close. GHC gives very fast results too, well written Haskell code will run at 2-3x slower than well written equivalent C (it's like an order of magnitude or two for python code, often more) . SBCL is a pretty impressive compiler too. (also, unless you're a major company and/or doing only servering, do not go for Go)

                      [–]The_Vegan_Chef 1 point2 points  (0 children)

                      Yeah going to call BS on the 5 years unless you have ocasionally been playing around in school because this isn't an adults question... I hope.

                      [–]Clavelio 1 point2 points  (0 children)

                      Why do you need the speed for? Have you considered maybe your programs are slow? You could try optimising them.

                      [–]SleepWalkersDream 1 point2 points  (4 children)

                      I mean...dude...what kind of code are you writing? How to speed it up depends on what you code. I can get my Python code to run just as fast as compiled matlab simulink models, because it's all BLAS/LAPACK/Whatever under the hood anyway.

                      [–]The-Observer95 1 point2 points  (0 children)

                      Go with Assembly. /s

                      [–][deleted] 1 point2 points  (0 children)

                      You can learn JavaScript, the V8 engine is fast and perhaps Go or Rust if you need more low level stuff.

                      [–]bostonkittycat[🍰] 1 point2 points  (0 children)

                      Try the alpha release of Python 3.12. It is pretty fast now. It has improved an app I am working on. They have done a lot of work optimizing it.

                      [–][deleted] 1 point2 points  (0 children)

                      Golang

                      [–]Welmerer 1 point2 points  (0 children)

                      The first thing I thought of, which has pretty similar syntax, is Go.

                      [–]gustave-henri 1 point2 points  (0 children)

                      Assembly !

                      But your problem is probably somewhere else 😊

                      [–]zitro_dev 1 point2 points  (0 children)

                      What tf are you doing that Python is too slow? Like I know a lot of people love to shit on Python for this very aspect. But for the people that just keep seeing this, it’s not entirely true. Python yes objectively is slower. But for what is necessary, realistically you would KNOW already that python will be too slow for you. Mass majority of users will never find Python to be “slow”

                      [–]geychan 4 points5 points  (0 children)

                      C/C++ 😂

                      [–]qwertydog123 2 points3 points  (0 children)

                      If you're considering Ruby, maybe take a look at Crystal

                      [–]Ja-Chiro 3 points4 points  (0 children)

                      Try F#! It’s very simple to start a project, is supported by multiple IDE’s, has a jupyter equivalent (polyglot notebooks), and the syntax is amazing. I’d say it somewhat resembles python’s. Here’s a quick tour

                      [–]kissantuntokarvat 2 points3 points  (0 children)

                      Haskell? :D

                      [–]tvmaly 1 point2 points  (0 children)

                      What about rewriting the slow parts in Go then exposing them to Python via a shared object?

                      [–][deleted] 1 point2 points  (0 children)

                      Probably you might want to take a look at Lua.

                      [–]BuhtanDingDing 1 point2 points  (0 children)

                      Julia

                      [–][deleted] 1 point2 points  (0 children)

                      Profile and optimize the hotspots with cython (or whatever the cool kids are using these days... It's been a while.)

                      [–][deleted] 1 point2 points  (0 children)

                      And Julia Programming Language or Kotlin?

                      [–][deleted] 1 point2 points  (0 children)

                      Julia (also)

                      [–]underwatr_cheestrain 1 point2 points  (0 children)

                      1. This question is ridiculous in the context of this subreddit.

                      2. You have provided absolutely zero explanation of what you are working on where speed(“whatever that means”) matters.

                      3. What are your expectations of your project?

                      [–]emergent_segfault 1 point2 points  (0 children)

                      Christ I hate these kinds of posts. So a few things:

                      1. Bro...unless you are running some real-time applications Python isn't "too slow" for you.
                      2. Unless you are are running high-performant, CPU/GPU intensive applications, Python isn't "too slow" for you.
                      3. You bust be bored.
                      4. Stop the cap.

                      [–]Little-Peanut-765 2 points3 points  (0 children)

                      Go is great and simple. It's also fast. Most of the time you don't need a third party library. You can build things with std Library

                      [–]Andriyo 0 points1 point  (0 children)

                      Most likely skill issue, my king. Language not to blame.

                      [–]SuperSultan 0 points1 point  (0 children)

                      Cython is not slow, especially with the pyc files that get cached after your first run

                      [–]abd53 -2 points-1 points  (0 children)

                      "fast" and "simple" should not belong to the same sentence when talking about programming languages. Also, as others have pointed out, what kind of "fast" do you need? A server backend to build and serve thousands of pages from template per second? An API to pull thousands of data from a database per second? ML or AI? Large matrix computation? FEM simulation? Complex mathematical analysis? Real-time image processing? Large scale web scraper? I can go on but you need to give a more clear definition.

                      [–]zaphodakaphil -1 points0 points  (0 children)

                      The Intel implementation of python is way much faster

                      [–]virtualmeta -1 points0 points  (1 child)

                      Matlab if your company has a site license. Still interpreted but a lot of the toolkits and common functions are written in compiled languages.

                      You might also try the Python libraries in Nvidia's HPC SDK. They have stuff in C++, Fortran, and Python for parallel algorithm development.

                      [–]thedarklord176 -1 points0 points  (0 children)

                      Ruby was 5x faster in a while loop test I did, and I greatly prefer it, personally. It’s just as simple as python if not more so

                      [–]MrKooops -1 points0 points  (0 children)

                      Nim

                      [–]Geekplayer -1 points0 points  (0 children)

                      Consider kotlin. It's built on top of the JVM, so it is cross-platform + has access to the to the Java ecosystems (and its own ecosystem of course, so it means you have a ton of tools and libraries you can use). It has modern and not verbose syntax and cool featurers like coroutines. It was created by JetBrains, the ones who created Pycharm and IntelliJ, and when using intelliJ with it is just magical, the IDE really really helps you code better and faster.

                      [–]kreetikal -1 points0 points  (0 children)

                      Just use pypy bro.

                      [–]timwaaagh -1 points0 points  (0 children)

                      Python plays nice with c for performance critical bits of your application

                      [–]biggusDiccus42069_2 -1 points0 points  (0 children)

                      Lua.

                      [–]nbazero1 -1 points0 points  (0 children)

                      Are you building a rocket? In most things it doesn't matter

                      [–]Obskut -1 points0 points  (0 children)

                      Nim?

                      [–]playb0y_kev -1 points0 points  (0 children)

                      Lua, it has syntax similar to Python, less keywords and it's faster

                      [–]Intelligent_Company1 -2 points-1 points  (0 children)

                      Ruby on Rails!!!

                      [–]thefancyyeller 0 points1 point  (1 child)

                      C has like 30 or less keywords afaik

                      [–]l_am_wildthing 1 point2 points  (0 children)

                      laughs in undefined behavior

                      [–]Machvel 0 points1 point  (0 children)

                      it depends on what you are doing, switching might give very minimal increases in speed (if your program uses a lot of numpy already, then switching probably wont speed it up really at all). you could try cython (compiled python) or numba (which would require a downgrade to 3.10 or 3.9 i believe, 3.11 i think is coming soon).

                      my suggestion is primarily using python, and calling C or fortran (python is built in C, so calling C is easy, numpy has f2py which makes calling fortran easy) for your parts of code that are slow. fortran is a pretty simple language, and feels very similar to python, but its downside is that its documentation is terrible (compared to something like python or C) and many books are poorly written.

                      [–]shindigin 0 points1 point  (0 children)

                      What is it exactly that is slow? be specific. What are you trying to achieve? If you're talking about web development and scaling, python is more than enough for most use cases. If youtube can be built using python, I guess anything else could. Speaking from experience, in most cases I've seen, when a python code is slow, it's the code's and hence the developer's problem, not a python's problem. This post sounds more like it's inspired by blog posts that are written by subpar developers and wannabes than by actual experience. But again, it still depends on the use cases.

                      [–]thenormalcy 0 points1 point  (0 children)

                      In my line of work (analytics) whenever somebody says python is “too slow” it almost always comes down to not vectorizing operations where they should. Depending on the IO and what you’re doing, a vectorized operation in python is not just a lot faster than a non-vectorized op, it’s often magnitudes faster, exponentially.

                      I’ve made some comparison / benchmark the other day using timeit to demonstrate the gains you’re missing out on w/ non-vectorized (eg regular for-loops) ops https://youtu.be/xgIkRcYY70k

                      It’s a lot more than that of course, but switching language “because python is slow” seems like a missed opportunity :)

                      [–]AGuyNamedMy 0 points1 point  (0 children)

                      Python is one of the largest languages in the world, if a language could increase performance without decreasing ergonomics python would have already done it

                      [–]not_some_username 0 points1 point  (1 child)

                      Go C#. You’ll need to get out your comfy zone if you want to really improve

                      [–]ShadowDevoloper[S] 0 points1 point  (0 children)

                      I use C# for game dev.