Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Implementing Benchmarking | Understanding and Measuring Performance
Optimization Techniques in Python

bookChallenge: Implementing Benchmarking

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:

  1. Complete the definitions of two functions:
    • The first, with for loop, should be named square_array_slow, and take a single parameter array;
    • The second, with vectorization, should be named square_array_fast, and take a single parameter array.
  2. Decorate both functions with the timeit_decorator and set its number parameter to 100.

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 4
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

close

Awesome!

Completion rate improved to 7.69

bookChallenge: 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:

  1. Complete the definitions of two functions:
    • The first, with for loop, should be named square_array_slow, and take a single parameter array;
    • The second, with vectorization, should be named square_array_fast, and take a single parameter array.
  2. Decorate both functions with the timeit_decorator and set its number parameter to 100.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 4
single

single

some-alt