Add Python benchmark
ci/woodpecker/push/woodpecker Pipeline was successful Details

Anthony Wang 2023-02-07 04:37:41 +00:00
parent 216eb8d0c9
commit 8c71408fb8
Signed by: a
GPG Key ID: 42A5B952E6DD8D38
1 changed files with 14 additions and 0 deletions

View File

@ -54,6 +54,20 @@ However, for other problems, like those annoying dynamic programming problems wi
A good rule of thumb is to count the number of basic operations, like additions, assignments, and loop iterations, that your solution is doing, and check if that's under 2*10^8 for C++. Java? 10^8. Python? Ugh, competitive programming is one of those things where Python becomes your worst enemy. You might not even be able to do 10^6 operations with Python.
Guess how long this Python translation of the above code takes:
N = 10**5
sum = 0
for i in range(N):
for j in range(N):
sum += i^j
Turns out this Python code takes *840.48 seconds*, which is over 800 times slower than the optimized C++ version. Maybe using Python for competitive programming might be a bad idea...
Of course, these are all just tips for estimating your runtime. The only way to know for sure is to submit it and see what happens. Still, there might not always be time in a contest to spend an hour implementing a borderline slow solution just to watch it get time limit exceeded for half the test cases. Keep in mind though that contest writers usually don't want their problems to boil down to tedious constant factor optimization. In USACO, the best strategy is probably to spend a bit more time thinking of better solutions, and then if you're still stuck, just implement the borderline slow solution to get as many points as you can. For Codeforces, where the scoring is all or nothing, it might not be worth it spending the time at all implementing something that probably won't pass every test case.
If you thought that was fun, check out this [performance estimation game](!