The computational cost here is indeed in generating the random numbers and managing the large arrays. At the end, list comprehensions are also for loops. In my hands now, calculating 1_000_000_000 samples:
1_000_000_000
# (...) for _ in range(times): insiders += perform(size) # gives pi ~= 3.14154544 Finished in: 40.36s
while,
# (...) insiders = sum(perform(size) for i in range(times)) # gives size: 25000000 pi ~= 3.141650028 Finished in: 41.85s
Cheers,
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The computational cost here is indeed in generating the random numbers and managing the large arrays. At the end, list comprehensions are also for loops. In my hands now, calculating
1_000_000_000
samples:while,
Cheers,