From 2594a89c3db9e469ad42bc2d94ba21e3603cfc15 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Tue, 26 Jan 2021 15:58:37 -0600 Subject: [PATCH] Add IRB Has Built-In Benchmarking With Ruby 3 as a ruby til --- README.md | 3 ++- ...b-has-built-in-benchmarking-with-ruby-3.md | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 ruby/irb-has-built-in-benchmarking-with-ruby-3.md diff --git a/README.md b/README.md index 7d60cd7..ddf8700 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud). -_1025 TILs and counting..._ +_1026 TILs and counting..._ --- @@ -835,6 +835,7 @@ _1025 TILs and counting..._ - [Iterate With An Offset Index](ruby/iterate-with-an-offset-index.md) - [Ins And Outs Of Pry](ruby/ins-and-outs-of-pry.md) - [Invoking Rake Tasks Multiple Times](ruby/invoking-rake-tasks-multiple-times.md) +- [IRB Has Built-In Benchmarking With Ruby 3](ruby/irb-has-built-in-benchmarking-with-ruby-3.md) - [Jump Out Of A Nested Context With Throw/Catch](ruby/jump-out-of-a-nested-context-with-throw-catch.md) - [Last Raised Exception In The Call Stack](ruby/last-raised-exception-in-the-call-stack.md) - [Limit Split](ruby/limit-split.md) diff --git a/ruby/irb-has-built-in-benchmarking-with-ruby-3.md b/ruby/irb-has-built-in-benchmarking-with-ruby-3.md new file mode 100644 index 0000000..4963e2b --- /dev/null +++ b/ruby/irb-has-built-in-benchmarking-with-ruby-3.md @@ -0,0 +1,26 @@ +# IRB Has Built-In Benchmarking With Ruby 3 + +As of Ruby 3.0.0, `irb`—Ruby's interactive console—comes with a `measure` +method. This can be used to turn the processing time feature on and off. With +it on, you can do rough benchmarking of how long different process take. + +Ruby `measure` or `measure(true)` to turn on the timing feature. + +```ruby +> measure +TIME is added. +=> nil +``` + +Once it is enabled, any command you run will including processing time details: + +```ruby +> array = [1,2,3,4] +processing time: 0.000033s +=> [1, 2, 3, 4] +> array.zip(array).map { |a,b| a * b ** (a * b) } +processing time: 0.000057s +=> [1, 32, 59049, 17179869184] +``` + +[source](https://jemma.dev/blog/irb-measure)