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

Course Content

Optimization Techniques in Python

Optimization Techniques in Python

1. Understanding and Measuring Performance
2. Efficient Use of Data Structures
3. Optimizing with Python's Built-in Features

bookChallenge: Implementing Benchmarking

Task

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:

  1. Define two functions:
    • The first, named square_array_slow, should take a single parameter array;
    • The second, named square_array_fast, should also take the same parameter.
  2. Decorate both functions with the timeit_decorator and set number to 100.

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
toggle bottom row

bookChallenge: Implementing Benchmarking

Task

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:

  1. Define two functions:
    • The first, named square_array_slow, should take a single parameter array;
    • The second, named square_array_fast, should also take the same parameter.
  2. Decorate both functions with the timeit_decorator and set number to 100.

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
toggle bottom row

bookChallenge: Implementing Benchmarking

Task

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:

  1. Define two functions:
    • The first, named square_array_slow, should take a single parameter array;
    • The second, named square_array_fast, should also take the same parameter.
  2. Decorate both functions with the timeit_decorator and set number to 100.

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!

Task

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:

  1. Define two functions:
    • The first, named square_array_slow, should take a single parameter array;
    • The second, named square_array_fast, should also take the same parameter.
  2. Decorate both functions with the timeit_decorator and set number to 100.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 1. Chapter 4
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
some-alt