From bbf05989284a0d3bd631fb93fa3f9f23ef1729ec Mon Sep 17 00:00:00 2001 From: j Date: Wed, 12 Apr 2023 10:24:29 +0200 Subject: [PATCH] Update page 'Day 7 homework' --- Day 7 homework.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Day 7 homework.md diff --git a/Day 7 homework.md b/Day 7 homework.md new file mode 100644 index 0000000..e47f27d --- /dev/null +++ b/Day 7 homework.md @@ -0,0 +1,10 @@ +Today's homework is to do some performance analysis of Python's hash tables, which are a key data structure used by the `dict` class. We're also going to do some miscellaneous tasks to help practice writing Python. + +1. Use the `time.perf_counter_ns()` method to measure how many nanoseconds it takes for `time.sleep()` to run for the following durations: 10 milliseconds, 100 milliseconds, 1 second. Repeat for 100 times for each of those durations. The variation in timing is called *jitter*. Can you find any pattern to how the jitter varies for each of the different sleep durations? Binning the results and creating a histogram may help. +2. Create a dict with 1 million integer keys, each with 64 bytes of random values. +3. Now that we know how to precisely time how long it takes for Python to do something, measure how long it takes to look up 1,000, 10,000, and 100,000 random integer keys, and repeat each experiment 100 times. Does the amount of time per key lookup change? +4. The ABC module can be used to create so-called *virtual base classes*, similar to the `Simulator.py` file from day 4. Look around you, and find two related objects. Create a virtual base class by inheriting from the ABC module and using the `@abstractmethod` and `@property` decorators to define the shared methods and properties of the class, and non-abstract methods and properties which are the same for the two objects. +5. Create *concrete classes* which inherit from your virtual base class from the previous task, and define the non-abstract methods and properties which are different for each of the two objects. I'm deliberately omitting an example here to incentivize you to read the documentation on the ABC module: https://docs.python.org/3/library/abc.html#module-abc +6. What happens when you try to call an abstract method, or access an abstract property in the base class? + +