Challenge: Implementing Benchmarking
Swipe to start coding
Let's practice benchmarking by comparing two approaches to squaring the elements of a NumPy array. The first approach, the slower one, uses a for
loop to square each element individually, while the second approach leverages vectorization. Don't worry if this concept sounds unfamiliarβwe'll discuss it later in the course.
Your task for now is the following:
- Define two functions:
- The first, named
square_array_slow
, should take a single parameterarray
; - The second, named
square_array_fast
, should also take the same parameter.
- The first, named
- Decorate both functions with the
timeit_decorator
and setnumber
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.69Awesome!
Completion rate improved to 7.69
Challenge: Implementing Benchmarking
Swipe to start coding
Let's practice benchmarking by comparing two approaches to squaring the elements of a NumPy array. The first approach, the slower one, uses a for
loop to square each element individually, while the second approach leverages vectorization. Don't worry if this concept sounds unfamiliarβwe'll discuss it later in the course.
Your task for now is the following:
- Define two functions:
- The first, named
square_array_slow
, should take a single parameterarray
; - The second, named
square_array_fast
, should also take the same parameter.
- The first, named
- Decorate both functions with the
timeit_decorator
and setnumber
to100
.
Solution
Thanks for your feedback!
single
Awesome!
Completion rate improved to 7.69
Challenge: Implementing Benchmarking
Swipe to show menu
Swipe to start coding
Let's practice benchmarking by comparing two approaches to squaring the elements of a NumPy array. The first approach, the slower one, uses a for
loop to square each element individually, while the second approach leverages vectorization. Don't worry if this concept sounds unfamiliarβwe'll discuss it later in the course.
Your task for now is the following:
- Define two functions:
- The first, named
square_array_slow
, should take a single parameterarray
; - The second, named
square_array_fast
, should also take the same parameter.
- The first, named
- Decorate both functions with the
timeit_decorator
and setnumber
to100
.
Solution
Thanks for your feedback!