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.
Bu egzersiz
Writing Efficient R Code
kursunun bir parçasıdırEgzersiz talimatları
The "movies.csv" and "movies.rds" files are available in your workspace.
- Load the
microbenchmarkpackage using thelibrary()function. - Using
microbenchmark(),read.csv(), andreadRDS(), 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 calledcompare.- In your call to
microbenchmark(), specifytimes = 10to call each function 10 times.
- In your call to
- Print
compareto see the results.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
# Load the microbenchmark package
library(___)
# Compare the two functions
compare <- microbenchmark(___,
___,
times = ___)
# Print compare
___