Skip to content

Instantly share code, notes, and snippets.

@vinhnglx
Last active September 19, 2023 06:46
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save vinhnglx/16283871d5872da491927ac9bab8bc39 to your computer and use it in GitHub Desktop.
Save vinhnglx/16283871d5872da491927ac9bab8bc39 to your computer and use it in GitHub Desktop.
Difference between Benchmarking and Profiling

Concepts

Benchmarking. We take two competing pieces of code - could be as simpler as a one liner or as complex as an entire web framework. Then, we put them up against each other (iterations per second). At the end of the task, we come up with a single metric, a score. We use the score to compare the two competing options.

In Ruby, the Benchmark module provides methods to measure and report the time used to execute Ruby code. http://ruby-doc.org/stdlib-2.0.0/libdoc/benchmark/rdoc/Benchmark.html

Profiling. Profiling your program is a way to determining which methods are called and how long each method take to complete. This way you can detech which methods are possible bottlenecks. Profiling also tell us a lot of valuable things, like what percentage of CPU time was use where, where memory was allocated and things like that.

In Ruby, Profiling your program will slow down your execution time considerably, so activate it only when you need it. https://ruby-doc.org/stdlib-2.1.0/libdoc/profiler/rdoc/Profiler__.html

In general

We should not use profiling to determine performance. Profiling is intented to be used in order to identify the parts of your program which take the most time.

When measuring performance, we only care about the speed of whole program taken together. Profiling in that case only skew result, instead, performance should be tested by benchmarks.

Refer:

http://programmers.stackexchange.com/questions/74697/can-software-performance-monitoring-profiling-be-automated-to-a-high-degree-as

https://ruby-doc.org/stdlib-2.1.0/libdoc/profiler/rdoc/Profiler__.html

http://ruby-doc.org/stdlib-2.0.0/libdoc/benchmark/rdoc/Benchmark.html

http://programmers.stackexchange.com/questions/74736/does-profiling-without-benchmarking-lead-to-micro-optimization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment