1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 23:28:02 +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

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