Follow

During a code review, I found code where we were using `Enumerable#find` to choose a value from an array, against data ; building a new Regex on each loop. When your array is sorted `` is orders of magnitude faster:

```
❯ ruby bm.rb
user system total real
justfind 25.743317 0.048932 25.792249 ( 25.791471)
bsearch 3.192201 0.003215 3.195416 ( 3.195469)
cache 0.285086 0.000304 0.285390 ( 0.285395)
```

Also, cache things when possible. 😅

Sign in to participate in the conversation
Ruby.social

A Mastodon instance for Rubyists & friends