1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 07:08:01 +00:00

Add IRB Has Built-In Benchmarking With Ruby 3 as a ruby til

This commit is contained in:
jbranchaud
2021-01-26 15:58:37 -06:00
parent 5c83237c70
commit 2594a89c3d
2 changed files with 28 additions and 1 deletions

View File

@@ -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)

View File

@@ -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)