Challenge: Implementing Benchmarking
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
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 7.69
Challenge: Implementing Benchmarking
Swipe to show menu
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
Thanks for your feedback!
single