Bird
0
0

You want to profile a method and also log the time taken each call. Which approach is best?

hard📝 Application Q9 of 15
Ruby - Ecosystem and Best Practices
You want to profile a method and also log the time taken each call. Which approach is best?
AWrap the method body with Benchmark.measure and print the result inside
BCall Benchmark.measure once outside all method calls
CUse sleep inside the method to simulate delay
DPrint time before and after method call without measuring
Step-by-Step Solution
Solution:
  1. Step 1: Understand per-call profiling

    To log each call's time, measure inside the method.
  2. Step 2: Compare other options

    Measuring once outside won't log each call; sleep simulates delay but not profiling; printing times without measuring is inaccurate.
  3. Final Answer:

    Wrap the method body with Benchmark.measure and print the result inside -> Option A
  4. Quick Check:

    Profile and log each call by measuring inside method [OK]
Quick Trick: Measure inside method to log each call's time [OK]
Common Mistakes:
  • Measuring outside calls
  • Using sleep to profile
  • Printing times without measuring

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes