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

bookChallenge: Implementing Benchmarking

Tarefa

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.

Solução

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 4
single

single

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

close

Awesome!

Completion rate improved to 7.69

bookChallenge: Implementing Benchmarking

Deslize para mostrar o menu

Tarefa

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.

Solução

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 4
single

single

some-alt