Commit 6a3fe1f
committed
Add Benchmark.ms method and enhance realtime with unit parameter
Rails previously included a monkeypatch that added a `ms` method to the
Benchmark module to return timing results in milliseconds instead of
seconds. This monkeypatch has been deprecated in Rails and will be
removed in future versions. ref: rails/rails@4cdf757
This commit adds native support for millisecond timing measurements by adding a new `Benchmark.ms` method
that returns elapsed time in milliseconds.
For web applications, measuring performance in milliseconds is much more helpful since the majority of operations happen in less than a second.
While it's acceptable to display times >1s as "1.2s", showing "0.125s" instead of "125ms" is significantly less readable and intuitive for
developers analyzing performance metrics.
```ruby
Benchmark.realtime { sleep 0.1 } #=> 0.10023
Benchmark.ms { sleep 0.1 } #=> 100.23
```
This change provides a clean migration path for Rails applications
currently relying on the deprecated monkeypatch while offering
enhanced functionality for all benchmark users.1 parent 4e39de6 commit 6a3fe1f
2 files changed
+20
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
325 | 325 | | |
326 | 326 | | |
327 | 327 | | |
328 | | - | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
329 | 342 | | |
330 | 343 | | |
331 | 344 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
159 | 165 | | |
160 | 166 | | |
161 | 167 | | |
| |||
0 commit comments