MulaiMulai sekarang secara gratis

Elapsed time

Using system.time() is convenient, but it does have its drawbacks when comparing multiple function calls. The microbenchmark package solves this problem with the microbenchmark() function.

Latihan ini adalah bagian dari kursus

Writing Efficient R Code

Lihat Kursus

Petunjuk latihan

The "movies.csv" and "movies.rds" files are available in your workspace.

  • Load the microbenchmark package using the library() function.
  • Using microbenchmark(), read.csv(), and readRDS(), compare the time it takes to import the CSV file with the time it takes to import the RDS file. Store the result as a variable called compare.
    • In your call to microbenchmark(), specify times = 10 to call each function 10 times.
  • Print compare to see the results.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Load the microbenchmark package
library(___)

# Compare the two functions
compare <- microbenchmark(___, 
                          ___, 
                          times = ___)

# Print compare
___
Edit dan Jalankan Kode