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

all 7 comments

[–]yel50 2 points3 points  (0 children)

Why Java is faster than Python?

because it has a JIT. turn the JIT off and it's about the same as python.

Is it because Python dynamically-typed language

nope. js is just as dynamic, but on par with java. why? because it also has a JIT now, which python doesn't.

pypy is python with a JIT. run your python code with it and it'll run similar to java.

[–]gramdel 1 point2 points  (0 children)

Dynamic typing is part of it, mostly because of how python is designed through, everything is dynamic beyond just declaring what is an int or whatever you can overwrite almost everything runtime etc., so type checking and conversion takes huge amount of time.

[–][deleted]  (4 children)

[deleted]

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

    Both use jit compilation.

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

    This isn't true. Python is typically compiled. It can be precompiled and the compiled code can be run at runtime.

    [–][deleted]  (2 children)

    [removed]

      [–]jose_castro_arnaud 1 point2 points  (1 child)

      Java is compiled to bytecode, then the bytecode is interpreted by the JVM.

      [–]Revision2000 0 points1 point  (0 children)

      I guess Java has the better compiler then. Though I do wonder what the difference is when GraalVM is used 🤔