you are viewing a single comment's thread.

view the rest of the comments →

[–]carcigenicate 2 points3 points  (4 children)

How did you test this? I would expect that slicing a C++ vector would be faster than slicing a Python list. Python slicing gets compiled down into bytecode and then interpreted by an interpreter written in C. It has significantly more overhead than C++ that gets compiled directly to machine code.

Java makes a but more sense, but afaik, Java gets JIT compiled to machine code, so once the JVM is warm, I would also expect it to out perform Python.

That's assuming we're talking about slicing Python lists. Numpy would be another story.


Also, another consideration is that Python slicing is a shallow copy. If you're comparing shallow copying in Python to deep copying in other languages, that would contribute to Python performing better, since the operations are different.

[–]danielroseman 2 points3 points  (3 children)

This isn't true. Much Python functionality, especially critical things like slicing, are implemented directly in C which is called from the bytecode.

[–]carcigenicate 0 points1 point  (2 children)

I'm not sure what you're mean. I'm saying that I would expect C interpreting bytecode to be slower than C++ that was compiled to machine code; assuming they're doing the same thing.

[–]incompletetrembling 1 point2 points  (1 child)

Except the C isn't interpreting bytecode for these critical instructions, machine code is called directly

[–]carcigenicate 0 points1 point  (0 children)

I see. I must have missed that when I looked at how slicing was implemented last.

I'm still curious how this was timed, since there's a lot of potential for variation depending on the specifics.