Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
@natan, I tested for that. I ran the two functions for thousands of numbers thousands of different times. I tested running them both in the same script. I tested them in separate scripts. I tested them varying the order in which they ran. I am not saying that replacing line breaks with semicolons will make all python code run faster on windows. I am saying that for these two particular functions, there is a consistent 5% difference between them on windows running python 3.11 where that 5% difference does not exist for these particular two functions on a linux system. I have no doubt that this difference might disappear with other code, slightly different code, or even different hardware.
I would not want to describe it as a windows thing. When you measure something you need to make sure it isn't being drowned out by other noise lest you measure the noise. You're not having a useful prediction falling out here, it's not like you can replace line breaks with semi colons and have it run faster on windows. The difference may disappear or reverse if you move things around, run it longer, take turns randomly, and so on.
@BobtheLantern thanks man for bringing more light into it ;p so its a windows thing, good to know. Thanks for the thread guys, we learn something new every day <3 anybody also on leedcode?
I ran the tests on two different machines, one running windows and one running linux. I confirmed that they both compiled to the same byte code on both machines (although with slightly different grouping as seen in b4b's fork above).
On the windows machine, the solution without the semicolon did run on average about 5% slower than the one with the semicolon, and this was consistent across many tests. On the linux machine, there was no difference between the solutions.
My best guess is that cpython acts differently enough between the two environments that the grouping of the bytecode causes different memory allocation and fetching behavior on each system, but I'm honestly out of my depth on this topic, so that's all it is - a guess.
Use spoiler flag next time. I've done it for you this time.
when you define t3 you use
halving_sum2
but when you print t3 you say it'shalving_sum1
, if you have to define something more than once that should immediately set off alarm bells about mixing them up.This comment is hidden because it contains spoiler information about the solution
Read my message again...
did you time it though? when i did back then it had different results..
Be serious guys...
If you get different results, that means you're doing something wrong.
Byte codes are strictly identical for both versions, and that is what is running "under the hood".
because the code does not need to change line when executing, less overhead
please let me know if you find the answer
guys why is the semicolon making my code faster in timeit?
Such a beautiful solution. Never thought bitwise operators can be so elegant.