News for hackers. Stuff that matters.
Re:Why Python is Slow: Looking Under the Hood (2014) by hasenj on Wednesday October 25, 2017 @07:45AM (#15549248)
Python is optimized for small programs being easy and quick (and pleasant) to write.

Every other use case it fails in some way. For being slow. For lacking static typing. For lacking compilation. For having a GIL. etc.

Re:Why Python is Slow: Looking Under the Hood (2014) by ptero on Wednesday October 25, 2017 @08:12AM (#15549379)
However, as posters in other thread said, the number and availability of libraries makes functionality of those small programs exceed that of much larger ones written in C or a similar language.

If you have to write a large project from scratch in Python it will be slow, but Python has gone pretty far in the direction where for many large tasks 90% of the functionality will be obtainable through standard libraries. Doing the remaining 10% in basic Python often keeps it competitive at runtime with compiled languages but produce much simpler, shorter and easier to maintain code.

Re:Why Python is Slow: Looking Under the Hood (2014) by weberc2 on Wednesday October 25, 2017 @08:29AM (#15549462)
Python has great libraries, but the claim that you can use them and have code that competes with compiled languages is flat out wrong. CPython is at least an order of magnitude slower than Java/Go/Haskell/etc and two orders slower than C/C++/Rust/etc. PyPy closes the gap a bit, but it's still noticeably slower than the aforementioned compiled languages.

Note to responders--HN won't let me respond to you, because "I'm posting too fast".

Re:Why Python is Slow: Looking Under the Hood (2014) by acdha on Wednesday October 25, 2017 @09:09AM (#15549748)
Those statements are too broad to be anything other than flamebait. Which specific code did you benchmark?

That’s not to say that CPython isn’t slower than a compiled language but in common usage the gaps usually end up being much smaller because most of us aren’t paid to run fib() and things like I/O dominate or code ends up being in the same C libraries (libjpeg, OpenSSL, etc.).

I’ve seen multiple cases where Python beat C/Go because the app used something like dictionaries which was heavily optimized C code in the standard library.

Again, compiled languages should usually win but the details matter, especially since most people don’t do the exact same work you do. Simply tossing around big numbers with no support contributes noise rather than insight to the conversation.

Re:Why Python is Slow: Looking Under the Hood (2014) by hasenj on Wednesday October 25, 2017 @10:41AM (#15550489)
> Which specific code did you benchmark?

I had a csv file with ~16k entries. Each entry has a lat, lon, name and id.

The task: given a (lat, lon) pair, list all entries within 5km.

The simplest straight forward solution is to iterate the list, measure the distance of each item to the given point, and add it to the return list if the distance is within the desired range.

No crazy optimization or anything.

The results were something roughly like this:

The D version runs in 2~4ms when compiled with optimizations turned on to the max, and about 6~8ms without optimizations (just default compiler settings).

The Go version runs in about 6~8ms. (The Go compiler has no option to produce optimized code).

The python version runs in about 50ms.

That's 10x slower than Go and 20x slower than D.

This is python 3. Using pypy shows absolutely no difference in performance.

Obviously the time to load the data from the csv file into a list is not counted in the above results.

> I’ve seen multiple cases where Python beat C/Go because the app used something like dictionaries which was heavily optimized C code in the standard library.

That's exactly backwards.

The Go and D versions use structs which are compact data structures that pack the data together. So the entire array fits in one contiguous block of memory.

Python has no concept of structs, so you have to deal with dictionaries.

In general, writing optimized code is not a good idea. You should almost always write the most plain and straight forward code.

Because fast languages are fast by default, there's no optimization required. The straight forward solution is fast enough.

If you are writing Python, your code will be slow by default. You will need to think about ways to optimize it if you want better performance.

Re:Why Python is Slow: Looking Under the Hood (2014) by hasenj on Wednesday October 25, 2017 @08:04PM (#15555343)
I cannot edit my previous comment but just now I revisited the code and noticed there was an import inside the function measuring the distance. One I moved the import out of the function, the execution time was cut by a bit more than half, to about 20ms.

The go version runs in about 3ms, not 6ms.

The D version runs in 2ms.

So overall the python version is 10x slower than native, not 20x slower.

Which is still kind of bad.

Re:Why Python is Slow: Looking Under the Hood (2014) by weberc2 on Wednesday October 25, 2017 @11:38AM (#15551000)
Worth noting that Python's csv library is optimized C, and it handily beats Go's so this benchmark must be dominated by non-CSV parsing.
Re:Why Python is Slow: Looking Under the Hood (2014) by hasenj on Wednesday October 25, 2017 @12:29PM (#15551543)
The csv parsing is not part of the benchmark.

The only thing I measured is iterating the list and matching entries within range of the input coordinate.

Re:Why Python is Slow: Looking Under the Hood (2014) by maxerickson on Wednesday October 25, 2017 @10:45AM (#15550534)
People talk about numpy as a numerical library, another way to think of it is as an api for interacting with contiguous chunks of memory.
Re:Why Python is Slow: Looking Under the Hood (2014) by tychver on Wednesday October 25, 2017 @01:41PM (#15552219)
The whole Ruby VM only takes ~50ms to start, so that sounds a bit slow. I wrote a quick version in Ruby and it only takes 5ms: https://gist.github.com/jamatthews/d910a2b39c87a871264dd31d1...
Re:Why Python is Slow: Looking Under the Hood (2014) by hasenj on Wednesday October 25, 2017 @07:56PM (#15555318)
It's a bit more complicated. I'm measuring geographical distances so I'm using haversine

    from math import radians, cos, sin, asin, sqrt
    def distance(lat1: float, lon1: float, lat2: float, lon2: float) -> float:
        # taken from: https://stackoverflow.com/a/4913653/35364
        # convert decimal degrees to radians
        lon1 = radians(lon1)
        lon2 = radians(lon2)
        lat1 = radians(lat1)
        lat2 = radians(lat2)
        # haversine formula
        dlon = lon2 - lon1
        dlat = lat2 - lat1
        a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
        c = 2 * asin(sqrt(a))
        r = 6371008 # Average radius of earth in meters
        return c * r
Re:Why Python is Slow: Looking Under the Hood (2014) by tychver on Saturday October 28, 2017 @09:04AM (#15575015)
Using Haversine distance increases it to only 13ms. I'm not sure why your Python implementation is so slow? In the real world, things like haversine are implemented as C extensions, so I wrote one for Ruby as a comparison and it runs in 3.8ms for 16k points. https://gist.github.com/jamatthews/d910a2b39c87a871264dd31d1...

The Ruby GIS libaries already have C implementations for haversine but I just wanted to show how easy it is to hook out to a C function for math heavy stuff.

Re:Why Python is Slow: Looking Under the Hood (2014) by hasenj on Wednesday November 01, 2017 @12:59AM (#15598879)
It was slow because at first I put the import inside the function. Moving it out improved the python performance to 20ms (as I mentioned in another comment).

The javascript version runs in 15ms.

> In the real world, things like haversine are implemented as C extensions

Having to write C-extensions is, well a point of friction, and adds complexity.

If you just used a native language to begin with, the simple straight forward code would work just fine.

Btw the source is here, and it also includes the csv file. https://bitbucket.org/hasenj/geodb/src

Re:Why Python is Slow: Looking Under the Hood (2014) by tychver on Wednesday November 01, 2017 @11:36AM (#15602235)
Yeah, that'll do it!

C extensions are a core part of Ruby. A big chunk of the std lib is implemented in C. You shouldn't be afraid of writing a tiny bit of C. Ruby and Python are scripting languages. They're literally designed for scripting another language.

The JIT for Ruby 3 is well underway, so in a bit it'll be a complete non-issue anyway.

Re:Why Python is Slow: Looking Under the Hood (2014) by weberc2 on Wednesday October 25, 2017 @01:51PM (#15552328)
> Those statements are too broad to be anything other than flamebait. Which specific code did you benchmark?

> Simply tossing around big numbers with no support contributes noise rather than insight to the conversation.

I resent that you characterize my comment as "flamebait" for lacking supporting evidence for my claim, when I was merely responding to your unsupported claim that Python competes with compiled languages. I chose to be broad because (as you point out), the range varies considerably by application and the margin for error is high, so it would be misleading to be artificially precise. It's perfectly reasonable that you want supporting evidence, but it doesn't make my post "lower quality" than yours.

As for "what I benchmarked", my comment was based on a decade of experience with these languages, including translating many proprietary systems from one language to another (sometimes a faster->slower language and sometimes a slower->faster language depending on whether I was optimizing for performance or security or maintainability).

> That’s not to say that CPython isn’t slower than a compiled language but in common usage the gaps usually end up being much smaller because most of us aren’t paid to run fib() and things like I/O dominate or code ends up being in the same C libraries (libjpeg, OpenSSL, etc.).

> I’ve seen multiple cases where Python beat C/Go because the app used something like dictionaries which was heavily optimized C code in the standard library.

I don't dispute that there are cases where Python beats naive C/Go. In particular, Python's csv lib is optimized C code, and it beats Go's CSV parser handily. If all you're doing is parsing CSVs and not actually calling into Python, you should probably stick with Python. While it's true that many applications are I/O bound, my figure was based on CPU time--it wouldn't make sense to judge languages by applications that are inherently I/O bound (although Go's async-by-default is much nicer than Python's async API). Besides, many applications are not I/O bound.

Re:Why Python is Slow: Looking Under the Hood (2014) by acdha on Wednesday October 25, 2017 @06:11PM (#15554755)
> I resent that you characterize my comment as "flamebait" for lacking supporting evidence for my claim, when I was merely responding to your unsupported claim that Python competes with compiled languages.

My point was simply that while it's easy to sit around talking about microbenchmarks that's not helpful for most developers. I've seen this cycle repeat so many times over the last couple decades because we're culturally prone to focusing on very small things and ignoring the larger picture:

Most developers are not employed to make a single thing as fast as possible but instead have to ship new features on a regular basis, handle a wide range of inputs correctly, etc.

Most of the performance problems people notice are due to application logic rather than low-level language characteristics, and that tends to mean things like I/O (API calls, poor file access patterns, etc.) or inefficient memory access patterns rather than how fast a loop can be.

I've seen slow applications in compiled languages replaced with a dynamic language and a big performance win not because of the underlying language characteristics but because writing in a lower-level (C, C++, Go) or more convoluted (Java J2EE) environment took enough longer that the development team was struggling just to complete features and the {Perl,PHP,Python,JS} team had considerably more time to optimize the core design.

I've also seen developers in all of those create huge labyrinths which made it hard to reason about the code's performance characteristics, and so my main concern these days is far less caring about the language than the overall amount of complexity you're asking developers to reason about and the related questions about the project and staffing.

Given unlimited time and budget, yes, a compiled language will probably win but for most projects the better question is “what tools will allow me to meet my goals with acceptable performance?” and that's a very different question.

Re:Why Python is Slow: Looking Under the Hood (2014) by weberc2 on Wednesday October 25, 2017 @08:15PM (#15555394)
> My point was simply that while it's easy to sit around talking about microbenchmarks that's not helpful for most developers.

To be clear, I never mentioned or implied microbenchmarks.

> Most developers are not employed to make a single thing as fast as possible but instead have to ship new features on a regular basis, handle a wide range of inputs correctly, etc.

I absolutely agree that performance is just factor among many, but the scope of this entire post is "performance". Most of your points seem to pertain to "the biggest performance problem I see is with poor engineering practices". This is definitely a problem, and you're right to prioritize addressing it over choosing a fast language. No language is going to fix stupid, although I will say that Go makes it less appealing to write stupid code, thanks to its restrictive type system. So once you've fixed your stupidity problem, the language-level problems will start to crop up. :)

And by the way, since you mentioned memory access patterns and I/O, I want to point out that these are also language-level concerns. Since everything in Python is a reference into a random location of heap, memory access performance is terrible. Go lets you specify whether something is a pointer or a value, which means you can specify which things are collocated. This is important for good cache performance. Regarding I/O, Python makes you choose between async for performance or sync and your process does no work until the I/O completes. Go lets you write normal synchronous code, and the runtime/scheduler make async calls under the hood so code which doesn't depend on the result of your I/O can execute while other code blocks.

> Given unlimited time and budget, yes, a compiled language will probably win but for most projects the better question is “what tools will allow me to meet my goals with acceptable performance?” and that's a very different question.

It is a very different question, but as new compiled languages improve on ergonomics without compromising performance and as new interpreted languages improve on performance without compromising ergonomics, the answer will increasingly become "not CPython" (Python is the fastest growing language in 2017, but that's largely due to a surge in data science popularity; however, since Python is popular with the data science community largely because of its libraries and not language features, other languages will catch up [and indeed are catching up] quickly).

Re:Why Python is Slow: Looking Under the Hood (2014) by igouy on Thursday October 26, 2017 @10:00AM (#15558838)
> To be clear, I never mentioned or implied microbenchmarks.

> As for "what I benchmarked", my comment was based on a decade of experience with these languages…

No doubt others have based their comments on their experience, which they trust more.

Re:Why Python is Slow: Looking Under the Hood (2014) by weberc2 on Thursday October 26, 2017 @01:24PM (#15561027)
I don't disagree; the parent asked where I got my estimates from and I answered.
Re:Why Python is Slow: Looking Under the Hood (2014) by igouy on Thursday October 26, 2017 @09:51AM (#15558765)
> Python is the fastest growing language in 2017, but that's largely due to a surge in data science popularity…

How do you know - "that's largely due to"?

Re:Why Python is Slow: Looking Under the Hood (2014) by weberc2 on Thursday October 26, 2017 @01:24PM (#15561042)
There were a lot of analyses that came out about this recently. I don't remember specific articles, but they floated around this and other fora. I think StackOverflow may have had one.
Re:Why Python is Slow: Looking Under the Hood (2014) by hyperpape on Wednesday October 25, 2017 @09:50AM (#15550078)
Unless you're using order of magnitude to mean 2x, it's not the case that Java/Go/Haskell are an order of magnitude slower than C/C++/Rust. You can see that on the benchmarks game, the techempower benchmarks, or this lovely paper on optimizing Haskell and C: http://www.leafpetersen.com/leaf/publications/ifl2013/haskel....
Re:Why Python is Slow: Looking Under the Hood (2014) by weberc2 on Wednesday October 25, 2017 @11:32AM (#15550947)
I agree that the average is probably around 2X, but the variance and margin for error are pretty large, so I approximated. I didn't mean to imply that there was exactly a tenfold difference.
Re:Why Python is Slow: Looking Under the Hood (2014) by whyever on Wednesday October 25, 2017 @10:38AM (#15550468)
> Unless you're using order of magnitude to mean 2x, it's not the case that Java/Go/Haskell are an order of magnitude slower than C/C++/Rust.

It depends, in some benchmarks they are 10 times slower.

Re:Why Python is Slow: Looking Under the Hood (2014) by hyperpape on Wednesday October 25, 2017 @11:41AM (#15551029)
And you can construct cases where the JVM is infinitely faster than C/C++/Rust, because the JIT optimizes through a virtual call and detects dead code.

Should we say that "it depends, in some cases, Java is infinitely faster than C/C++/Rust"? Not unless we want to deliberately obscure the issue (or we want to warn someone about strange results). Benchmarks are about finding representative results across a variety of tasks.

If you think there are good benchmarks that show these languages are 10x slower in realistic cases, then you should share them, rather than just asserting that they're out there.

Re:Why Python is Slow: Looking Under the Hood (2014) by whyever on Wednesday October 25, 2017 @03:03PM (#15553114)
> Benchmarks are about finding representative results across a variety of tasks.

> And you can construct cases where the JVM is infinitely faster than C/C++/Rust, because the JIT optimizes through a virtual call and detects dead code.

How would that be a "representative result across a variety of tasks" according to your own definition of a benchmark? What do you mean by "across a variety of tasks"? That sounds like taking the average of some metric for different benchmarks, I'm not sure that is a good idea. I think it makes more sense to benchmark your specific use case, which is what I meant by "it depends".

> If you think there are good benchmarks that show these languages are 10x slower in realistic cases, then you should share them, rather than just asserting that they're out there.

I never said anything about "realistic" and "good", but they are really not unthinkably hard to find: http://benchmarksgame.alioth.debian.org/u64q/binarytrees.htm...

Re:Why Python is Slow: Looking Under the Hood (2014) by weberc2 on Wednesday October 25, 2017 @01:36PM (#15552162)
This is kind of my point; the variance and error margin are pretty wide. Specifying "2x" implies a precision I can't vouch for, so I settled for "an order of magnitude" as the general ballpark. If the 2x figure is important to you, I'm happy to make that concession.
Re:Why Python is Slow: Looking Under the Hood (2014) by hyperpape on Wednesday October 25, 2017 @01:48PM (#15552296)
I get the concern, but I'd say "a few times slower", which suggests 2x/3x/4x, not "an order of magnitude", which suggests something like 8x or 20x or whatever.
Re:Why Python is Slow: Looking Under the Hood (2014) by Can_Not on Wednesday October 25, 2017 @05:21PM (#15554391)
Orders of magnitude actually suggest the data would be best measured in exponents such as 10^3, 10^4, 10^5, etc because of it's range and distribution.
Re:Why Python is Slow: Looking Under the Hood (2014) by ptero on Wednesday October 25, 2017 @09:13AM (#15549772)
Can you provide some pointers / examples? This is an honest question -- I am not an expert on bare computation speed, but this (two orders of magnitude vs C++) has not been my experience.
Re:Why Python is Slow: Looking Under the Hood (2014) by igouy on Wednesday October 25, 2017 @02:57PM (#15553063)
A broad range -- Python programs are "as-fast-as-C" when they are C :-)

http://benchmarksgame.alioth.debian.org/u64q/compare.php?lan...

Re:Why Python is Slow: Looking Under the Hood (2014) by whyever on Wednesday October 25, 2017 @10:41AM (#15550490)
Re:Why Python is Slow: Looking Under the Hood (2014) by baldfat on Wednesday October 25, 2017 @08:38AM (#15549514)
DEPLOYMENT

My ONE HUGE Gripe with Python. This and that Pandas (I understand why BUT it drove me away) Zero based for statistical work. Your math is 1 based and the language is 0 based.

Re:Why Python is Slow: Looking Under the Hood (2014) by peatmoss on Wednesday October 25, 2017 @09:12AM (#15549765)
It’s funny because deployment is one of the reasons I hear Python data people trash on R. In general, I’d agree with them that it’s slightly harder for systems people to grok R, but on the other hand I don’t exactly see Python as a shining beacon.
Re:Why Python is Slow: Looking Under the Hood (2014) by baldfat on Wednesday October 25, 2017 @06:06PM (#15554724)
R as a Domain Specific Language has great output for Reports, Word Documents or Power Point slides and a million of reports. There is also the shinny package and shinny server for web publishing.

This is why I went to R from Pandas. My company was impressd with all the reports but asked why they couldn't edit the themes. Then I did it in R in 2 days and haven't looked back. I love Python but I have been using it less and less and more Racket.

Re:Why Python is Slow: Looking Under the Hood (2014) by peatmoss on Wednesday October 25, 2017 @08:35PM (#15555475)
Haha, yes, I keep encountering your comments about R and Racket and have to do a double take to make sure you’re not me.

Would love to hear more about any data Racketeering you’re doing. I’ve been thinking of documenting up my wishlist for quanty things in Racket and maybe try implementing a data dsl in Racket.

Re:Why Python is Slow: Looking Under the Hood (2014) by baldfat on Thursday October 26, 2017 @12:21PM (#15560303)
I am thinking of doing a munging and data cleaning dsl and using OpenRefine as a way to implement the code. I really think that would be super handy for doing data cleaning.

A few people have done some R calls within Racket that is intresting.

Re:Why Python is Slow: Looking Under the Hood (2014) by peatmoss on Thursday October 26, 2017 @03:48PM (#15562357)
Let me know if you feel like combining forces either for implementation or for imagineering :-)

EDIT: I also know there’s a data frame package called munger, though I it’s undocumented and likely incomplete.

Re:Why Python is Slow: Looking Under the Hood (2014) by hasenj on Wednesday October 25, 2017 @11:05AM (#15550710)
Yup! This is what I meant by "lacking compilation".

For example, in Go, you can produce a single statically linked executable and run it on the server directly. No need for a dev-ops/infra team.

Re:Why Python is Slow: Looking Under the Hood (2014) by psynapse on Wednesday October 25, 2017 @03:33PM (#15553345)
Our Go code is built and tested by Jenkins. If green, the build is stored in an artefact repository. Another job is triggered to update the version in Puppet on potentially multiple targets.

The Puppet module is responsible for getting the binaries from the artefact repository, deploying them with config for the environment, running them as systemd units and shipping the journald output to Elasticsearch.

Static compilation does not obviate devops.

Re:Why Python is Slow: Looking Under the Hood (2014) by hasenj on Wednesday October 25, 2017 @10:42PM (#15555950)
Sounds like you have a lot of unnecessary cruft in your infrastructure.
Re:Why Python is Slow: Looking Under the Hood (2014) by throwaway894345 on Wednesday October 25, 2017 @09:42AM (#15549997)
Deployment and reproducible builds were so bad for us that we switched to Nix. It largely solved the problem, but it has us doing a lot of work to maintain our Nix infrastructure and definitions.
Re:Why Python is Slow: Looking Under the Hood (2014) by billfruit on Wednesday October 25, 2017 @10:08AM (#15550216)
Precisely the opposite reason R drove me away. R uses 1 based indexing.Seriously we should all be using Zero based indexing for all purposes.
Re:Why Python is Slow: Looking Under the Hood (2014) by peatmoss on Wednesday October 25, 2017 @11:17AM (#15550814)
One can make an appeal to aesthetics, but that’s no differentiator.

Or one could appeal to adherence to existing standards. Fortran is the oldest (portable) programming language and was 1-based.

Or one could appeal to consistency with the problem domain. Again, math [EDIT: indices are] 1-based.

Zero-based is consistent with C, but that’s about the best argument I can make for zero-based.

Re:Why Python is Slow: Looking Under the Hood (2014) by billfruit on Wednesday October 25, 2017 @11:05PM (#15556046)
I think Dijkstra established the case for using Zero based indexing strong enough: https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/E...
Re:Why Python is Slow: Looking Under the Hood (2014) by DonbunEf7 on Wednesday October 25, 2017 @12:11PM (#15551373)
Maths is zero-based. I'm not sure why you think that numbers start with one; every formulation of the integers in modern maths starts with zero.
Re:Why Python is Slow: Looking Under the Hood (2014) by peatmoss on Wednesday October 25, 2017 @12:18PM (#15551446)
Matrices, common in statistics because of applications of linear algebra, have long maintained the convention of i,j indexes starting with one.
Re:Why Python is Slow: Looking Under the Hood (2014) by dnautics on Thursday October 26, 2017 @12:12AM (#15556288)
It's not. Zero based is wise for offsets (CS) and fields where you have a zero element, and a few corner cases like factorial, but by and large any time you're enumerating an order over a nonempty set you start with one in math, because, max(indices) = |set|
Re:Why Python is Slow: Looking Under the Hood (2014) by baldfat on Wednesday October 25, 2017 @06:08PM (#15554740)
0 based was only for programming for iterations. This makes it a weird math for people. When the first column is 0 and 1 is the second column it is indeed weird and is why statistical languages are 1 based.
Re:Why Python is Slow: Looking Under the Hood (2014) by anewhnaccount2 on Wednesday October 25, 2017 @08:02AM (#15549330)
This is too categorical. And also it fails to define when small stops being small (and so is easy to defend by moving the goalposts). Yes, these are real problems, but some of them have (partial) solutions. You can use one of the many solutions to write a C, C++, cython and so on extension. You can have type checking with mypy. You can produce executable with cx_freeze (not compilation, but compilation is more of a solution than a problem). You can create parallel programs using multiprocessing. (etc.)
Re:Why Python is Slow: Looking Under the Hood (2014) by weberc2 on Wednesday October 25, 2017 @08:24AM (#15549436)
Writing extensions in c/c++ largely negates all stated benefits of using Python in the first place, and I'm proficient in all three languages. Further, mypy is hopeful, but it's not quite there yet (lots of holes and bugs--notably no support for recursive types). Lastly multiprocessing for parallelism is a poor man's solution, and far from what I've become accustomed to in Go, Rust, etc. Python is a nice language and it pays my bills, but Go beats it at many of its own purported strengths, in my opinion.
Re:Why Python is Slow: Looking Under the Hood (2014) by hasenj on Wednesday October 25, 2017 @10:27AM (#15550367)
Using these solution makes the development process much more troublesome than it needs to be, thus defeating the whole point of using python.
Re:Why Python is Slow: Looking Under the Hood (2014) by dr_zoidberg on Wednesday October 25, 2017 @08:16AM (#15549399)
Working in digital forensics, I read your comment and immediately thought of Volatility and Rekall, the most important memory forensics frameworks. Both monsters that can analize memory dumps from very different operating systems and microprocessor architectures, supporting a wealth of plugins/extensions to analyze every bit of information you can think of. Both written in Python. Please, tell me how they are failing.
Re:Why Python is Slow: Looking Under the Hood (2014) by datawarrior on Wednesday October 25, 2017 @11:19AM (#15550832)
That's largely because Rekall is a fork of Volatility, not because Python was better suited to the task for both projects. Python is used heavily in security/forensics work so it was just a natural choice for the developers.

I'm not sure what your argument is otherwise. If there was a tool written in C or Rust to benchmark against then we could better argue which is better for the task. I don't think anyone said Python was "failing."

Re:Why Python is Slow: Looking Under the Hood (2014) by dr_zoidberg on Wednesday October 25, 2017 @06:15PM (#15554775)
My point is that both of them are big, succesful projects, written in Python, in contrast to hasenjs comment that anything that isn't "a small program being easy and quick (and pleasant) to write... fails in some way.".
Re:Why Python is Slow: Looking Under the Hood (2014) by bluedino on Wednesday October 25, 2017 @08:33AM (#15549487)
Is it really slow? I ported a bunch of code from PHP to Python, nothing incredibly complicated, but it was easy to switch and the Python code all ended up running about 25-40% faster.

I'm sure it would have been even faster to use Java or something like that but it would have taken 5 times as long, and I would have needed to know a lot more Java than Python.

Re:Why Python is Slow: Looking Under the Hood (2014) by weberc2 on Wednesday October 25, 2017 @08:43AM (#15549543)
Yeah, slow is relative. PHP is no one's standard for "fast". I program in Python by day, and I find Go much easier to work with, and it's roughly 10 times faster. There are other performant options besides Java these days.
Re:Why Python is Slow: Looking Under the Hood (2014) by jack9 on Wednesday October 25, 2017 @10:15AM (#15550273)
> PHP is no one's standard for "fast".

PHP is my standard for "fast" in the realm of scripting. Just behind Perl. Python is slower in every prototype benchmark we have ever tried. It's a practical problem that hand waving cannot remedy.

Re:Why Python is Slow: Looking Under the Hood (2014) by hasenj on Wednesday October 25, 2017 @10:30AM (#15550390)
Fast would be something like Go or D or any of the other compiled languages.
Re:Why Python is Slow: Looking Under the Hood (2014) by jack9 on Wednesday October 25, 2017 @12:09PM (#15551346)
I'm not sure how that relates. None of those are scripting languages, although when you start talking about "compiled" it gets a little messy with definitions. Either way, it's not what I'm talking about.
Re:Why Python is Slow: Looking Under the Hood (2014) by weberc2 on Wednesday October 25, 2017 @01:33PM (#15552139)
You're the one who invoked "scripting" out of the blue. There's no reason to artificially limit the conversation to scripting languages, especially since "scripting" is itself poorly defined (what constitutes a scripting language? An interpreter? Where do interpreters end and VMs begin? Python's "interpreter" is a VM; is Python not a scripting language? Python even compiles to Python bytecode--is Python then a compiled language?). If you're going to scope the languages being evaluated, do it by something meaningful, like problem domain--for example, "web applications". I can't speak to D, but Go is certainly a competitor in this space, and speaking from experience, it's much, much more performant than Python and PHP by virtually all metrics. Maybe you mean data science, in which case Python and Go can be compared, but I don't know that anyone is doing real data science work in PHP. Maybe you mean "general purpose language", in which case all of the previously discussed languages can be compared, and in which case Go and D completely outclass Python and PHP.
Re:Why Python is Slow: Looking Under the Hood (2014) by jack9 on Thursday October 26, 2017 @12:47PM (#15560609)
> You're the one who invoked "scripting" out of the blue.

Not at all. It naturally follows from the incorrect assertion that

> > PHP is no one's standard for "fast".

except within a set of constraints...like scripting languages (of which the pointless bikeshedding often and has occurred).

> There's no reason to artificially limit the conversation to scripting languages,

You've just decided to derail a discussion of a finer point and claim it's in the interest of the main conversation because it's not the main discussion. I can only assume is that you like to argue and had nothing better to do. Good Luck with that.

Re:Why Python is Slow: Looking Under the Hood (2014) by weberc2 on Friday October 27, 2017 @08:43AM (#15567734)
You introduced an arbitrary, irrelevant constraint as though it was the only valid criterion and got called on it. No need to be sore about it.
Re:Why Python is Slow: Looking Under the Hood (2014) by cygx on Wednesday October 25, 2017 @02:59PM (#15553079)
what constitutes a scripting language?

It's indeed a bit fuzzy, but program execution without separate compilation (which is not a feature of a language per se) is something I'd look for.

As far as intrinsic language features go, a lack of boilerplate in the sense of

    print("hello")
vs

    class Hello {
        public static void main(String[] args) {
            System.out.println("hello");
        }
    }
is a good indicator, as is dynamic typing.
Re:Why Python is Slow: Looking Under the Hood (2014) by weberc2 on Wednesday October 25, 2017 @03:23PM (#15553263)
This isn't a meaningful definition because compilation and execution under a single command is trivial for any compiled language, including Go and Python and PHP. As for lack of boilerplate, Haskell and many statically-typed, compiled functional languages have less boilerplate than PHP or Python. Dynamic typing is more meaningful, but regardless of definition, I fail to see why it's useful to restrict the scope to scripting languages. However, even if you make this restriction, there are many, many languages that are dynamically typed "scripting" languages that are much faster than PHP and Python (JRuby, Lua, JS, Wren, most lisps, etc).
Re:Why Python is Slow: Looking Under the Hood (2014) by igouy on Wednesday October 25, 2017 @03:51PM (#15553495)
> dynamically typed "scripting" languages that are much faster than PHP and Python (JRuby

?

http://benchmarksgame.alioth.debian.org/u64q/compare.php?lan...

Re:Why Python is Slow: Looking Under the Hood (2014) by weberc2 on Wednesday October 25, 2017 @04:24PM (#15553853)
That's not the graal backend. The TruffleRuby project uses Graal to make JRuby much, much faster. I don't know what the specific information, but generally "competitive with Java" is my understanding. Perhaps "TruffleRuby" is the name I should have used; it's not apparent and I'm only nominally familiar with the project.
Re:Why Python is Slow: Looking Under the Hood (2014) by igouy on Wednesday October 25, 2017 @04:34PM (#15553968)
Current Status: "TruffleRuby is progressing fast but is currently probably not ready for you to try running your full Ruby application on."

https://github.com/graalvm/truffleruby#current-status

Re:Why Python is Slow: Looking Under the Hood (2014) by weberc2 on Wednesday October 25, 2017 @05:22PM (#15554399)
Ok, I was wrong about Ruby, but my point stands--Python and PHP are not even "speed demons" of the so-called scripting languages.
Re:Why Python is Slow: Looking Under the Hood (2014) by hasenj on Wednesday October 25, 2017 @10:45PM (#15555963)
D and Go compilers can both run a script seamlessly without a visible compilation step (it still happens, but behind the scenes, and compilation is fast enough that you would not even notice it).
Re:Why Python is Slow: Looking Under the Hood (2014) by cygx on Thursday October 26, 2017 @02:40AM (#15556868)
That's what makes it fuzzy.

I would argue that the defining characteristic of a scripting language is the ability to execute scripts instead of generate binaries. You could then make a further distinctions between application scripting languages (the origin of Lua and Javascript) and general-purpose scripting languages (which are independent of a host application - think Perl or Python).

This distinction is not sharp: Today, Lua and Javascript are used as general-purpose scripting languages, people ship 'fakecutables', packaging script and runtime system into a binary, and even C++ has been used to script applications (physicists are silly people ;)).

But there's normally still a dominant usage pattern associated with a given language, so the classification is not entire useless.

Re:Why Python is Slow: Looking Under the Hood (2014) by hasenj on Wednesday October 25, 2017 @10:45PM (#15555968)
It relates because we are not talking about scripting. We are talking about programming.

Python/Ruby/etc.. are slow.

D/Go/C/Rust/etc.. is fast.

Re:Why Python is Slow: Looking Under the Hood (2014) by jack9 on Thursday October 26, 2017 @12:42PM (#15560538)
I constrained my point. You are now making your own determination. Good Luck with that.
Re:Why Python is Slow: Looking Under the Hood (2014) by zerkten on Wednesday October 25, 2017 @09:24AM (#15549853)
What are you actually programming? You mention some languages, but you don't actually give any context.
Re:Why Python is Slow: Looking Under the Hood (2014) by igouy on Wednesday October 25, 2017 @03:01PM (#15553096)
I wonder which version of PHP you were using?
Re:Why Python is Slow: Looking Under the Hood (2014) by cygx on Wednesday October 25, 2017 @09:44AM (#15550014)
PHP is supposedly faster than Python, nowadays. Not at the JS or LuaJIT level, but it eats CPython and CRuby for breakfast.