1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Testing in Python

Connected

Exercise

Speed of loops

Of course, set is better suited for searching elements. It is based on hashes, so you can expect constant complexity most of the time. But what about iterating over all the object's elements? Let's compare the speed of loop iteration over the elements of list and set with pytest and pytest-benchmark. The pytest package has already been imported.

Instructions

100 XP
  • Add @benchmark decorator before the functions starting with iterate_.
  • Complete the loops in iterate_list and iterate_set.