1. Learn
  2. /
  3. Courses
  4. /
  5. Intermediate Julia

Exercise

Timing a function

Timing our code is critical as slow code can provide a poor experience for a user, or a script could be running far longer and less efficiently than it should. One of the major benefits that we want to take advantage of in Julia is its speed, so being able to accurately benchmark your code is even more important.

Now that you've seen the different options that are available for benchmarking, let's try it ourselves with some examples.

In the first step, use the base package @time macro to time the function my_function. In the second step, use the BenchmarkTools package to time the same function my_function.

We have already imported the BenchmarkTools package for you.

Instructions 1/2

undefined XP
  • 1
    • Time the function my_function using the base time macro.
  • 2
    • Time the function my_function using the BenchmarkTools benchmark macro. Specify the number of samples as 1000 using samples=1000 after the function name.