Please ignore secret bonuses. Secret tests do NOT award bonus. Max hw grade is 30+2 bonus efficiency

Do you need help?

Notice Board

Per partecipare al corso di Fondamenti di programmazione 2023-24 loggatevi e attivatelo nella vostra pagina dei corsi preferiti. A quel punto il corso appare nel menù personale cliccando sul proprio avatar. Per i materiali degli anni precedenti seguite lo stesso metodo.

To join the Programming/Lab 2023-24 course, log-on and select it on the my courses page. It will appear on the personal menu of your avatar. For earlier years use the same method.

Is it allowed to use caching in HW8?

aryanahamed (7920 points)
6 12 67
in HW8 by (7.9k points)
closed by
For the caching either I need to use a global variable or add new parameters in the pre-defined function. Is it allowed?
221 views
closed

3 Answers

Best answer
andrea.sterbini (208020 points)
756 1270 2377
by (208k points)
selected by
you can use caching internally, to speed up your pharaohs_cypher, but you CANNOT use it to remember partial results to be used in a following test run (which we execute to compute the average execution time).

Thus the caching test will fail if your defaults, global variables or class attributes (or any other global attribute) change before and after the execution of pharaohs_revenge.
AL1990 (28120 points)
3 6 142
by (28.1k points)
edited by
Caching is prohibited between test runs, but is allowed during a test run.
Actually, global variables can be used but not for caching between test runs, they should not change between before and after a test run.
Nago (1690 points)
7 14 20
by (1.7k points)
edited by
So we are allowed to use global variables as long as their values don't change?

For example, can I use any dictionary as a global variable?
AL1990 (28120 points)
3 6 142
by (28.1k points)
edited by
Global variables with mutable values could introduce side-effects, but if the elements of your 'global' dictionary don't change between before and after the execution of the pharaohs_revenge function, that's fine.
However, if your dictionary is empty at the beginning of the test run, you need to clear the data in it at the end.
D
David_ (2960 points)
2 4 8
by (3.0k points)
From what is said here: https://q2a.di.uniroma1.it/30035/tests-caching-and-timing , it's prohibited