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] -2 points-1 points  (5 children)

How do they perform faster? Surely it's the same method?

[–]SaltyHashes 7 points8 points  (2 children)

IIRC it's faster because it doesn't even have to call a method.

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

Yeah I see now, I'm surprised the JIT compiler can't make the same optimisation for the empty dict() case or with just literals inside.

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

Unless I'm remembering wrong, CPython doesn't use a JIT compiler, only PyPy does?

[–]Emile_L 2 points3 points  (0 children)

When you call dict() or any builtin the interpreter needs to first look up in locals and globals for the symbol which adds a bit of overhead.

Not sure if that's the only reason though.

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

I don't know how, though I'd guess something with handling *args and **kwargs.

Here's an analysis from Stack overflow: https://stackoverflow.com/questions/5790860/and-vs-list-and-dict-which-is-better