3 ms·
What happens if you lift the regexp out of the block and reuse the same regexp instance?
by yxhuvud 8y ago
What happens if you lift the regexp out of the block and reuse the same regexp instance?
- cutler 8y agoTried: regex = Regexp.new '\b\w{15}\b' IO.foreach('logs1.txt') {|x| puts x if regex.match? x } ... but performance and RAM usage were identical.
- JohnBooty 8y agoRuby's smart enough to freeze regexen by default. I think that landed around 2.0/2.1/2.2 pry(main)> 3.times { puts /i_am_a_reg_ex/.object_id } 70131978677720 70131978677720 70131978677720