python.exe
and pythonw.exe
are optimizing the code before running. It seems that the 2**100000000
is being pre-computed. This small edit to the code:
import time
print("program entered")
def ispow2(n):
return not n & n - 1
start = time.perf_counter()
ispow2(2**100000000)
end = time.perf_counter()
print(end - start)
Produces the following output completely after the wait:
program entered
0.01701506924359556
So the program doesn't even run until after the majority of the wait.
Data that suggests that this is with the 2**...
part (running from command line):
power of two|approximate wait time|reported time
1000000000 | 6 seconds |0.1637752267742188
10000000000 | 62 seconds |1.6400543291627092
On that last run, there was a clear ~1.5
second wait between the output of program entered
and 1.6400543291627092
.