Skip to main content
added 146 characters in body
Source Link

They are equivalent. The heavy lifting here to calculate the key hash. In both sections, it happens twice: add to a dict and then add to set. Other procedures should be light. You can use debugger to show the C calls to verify.

In addition to function call overhead mentioned by Carcigenicate, memory management might also play a role. If the set knows the length, it could possibly avoid copying data over when the predefined space isn't enough.

They are equivalent. In both sections, add to a dict and then add to set.

In addition to function call overhead mentioned by Carcigenicate, memory management might also play a role. If the set knows the length, it could possibly avoid copying data over when the predefined space isn't enough.

They are equivalent. The heavy lifting here to calculate the key hash. In both, it happens twice: add to a dict and then add to set. Other procedures should be light. You can use debugger to show the C calls to verify.

In addition to function call overhead mentioned by Carcigenicate, memory management might also play a role. If the set knows the length, it could possibly avoid copying data over when the predefined space isn't enough.

Source Link

They are equivalent. In both sections, add to a dict and then add to set.

In addition to function call overhead mentioned by Carcigenicate, memory management might also play a role. If the set knows the length, it could possibly avoid copying data over when the predefined space isn't enough.