Section 1. Chapter 4
single
Challenge: Implementing Benchmarking
Swipe to show menu
Task
Swipe to start coding
You have definitions for two functions. Both functions return a copy of the original array with its elements squared. The first approach, the slower one, uses a for loop to square each element individually, while the second approach leverages vectorization.
Your task is to perform a benchmark of both functions. To do this:
- Complete the definitions of two functions:
- The first, with
forloop, should be namedsquare_array_slow, and take a single parameterarray; - The second, with vectorization, should be named
square_array_fast, and take a single parameterarray.
- The first, with
- Decorate both functions with the
timeit_decoratorand set itsnumberparameter to100.
Solution
Everything was clear?
Thanks for your feedback!
Section 1. Chapter 4
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat