From 3c73cc28e0bf12d54f344135b35c5af8feaf0a77 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sun, 14 Apr 2013 18:20:09 -0500 Subject: [PATCH] Optimization: avoid repeated interpolation in regexp Benchmark.bm do |b| b.report("before") do 100_000.times { /(\.#{MacOS.cat}\.bottle\.(\d+\.)?tar\.gz)$/ } end b.report("after ") do 100_000.times { /(\.#{MacOS.cat}\.bottle\.(\d+\.)?tar\.gz)$/o } end end user system total real before 35.400000 0.140000 35.540000 ( 35.619674) after 0.020000 0.000000 0.020000 ( 0.016662) --- Library/Homebrew/bottles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/bottles.rb b/Library/Homebrew/bottles.rb index 32b6f84717..159654c48b 100644 --- a/Library/Homebrew/bottles.rb +++ b/Library/Homebrew/bottles.rb @@ -63,7 +63,7 @@ def bottle_suffix revision=nil end def bottle_native_regex - /(\.#{MacOS.cat}\.bottle\.(\d+\.)?tar\.gz)$/ + /(\.#{MacOS.cat}\.bottle\.(\d+\.)?tar\.gz)$/o end def bottle_regex