Permalink
Browse files

Minimize calls to String#split

old:
~/dev/agent_prof [master*] $ for i in {1..3};do  ruby nr_bm.rb ; done
      user     system      total        real
instrumented  7.110000   0.080000   7.190000 (  7.177364)
      user     system      total        real
instrumented  7.150000   0.080000   7.230000 (  7.218395)
      user     system      total        real
instrumented  7.040000   0.080000   7.120000 (  7.111533)

new:
~/dev/agent_prof [master*] $ for i in {1..3};do  ruby nr_bm.rb ; done
      user     system      total        real
instrumented  7.000000   0.080000   7.080000 (  7.076323)
      user     system      total        real
instrumented  7.080000   0.080000   7.160000 (  7.148165)
      user     system      total        real
instrumented  6.990000   0.080000   7.070000 (  7.054725)
  • Loading branch information...
1 parent 8a90402 commit dde6ac719084d3fae3650876d11645b9b3e9a4af Sam Goldstein committed Mar 12, 2012
@@ -81,9 +81,12 @@ def category
segments[0]
end
+
+ EMPTY_SEGMENTS_HASH = [].freeze
+ SEGMENTS_CACHE = {}
def segments
- return [] if !name
- @segments ||= name.split(SEPARATOR).freeze
+ name || (return EMPTY_SEGMENTS_HASH)
+ SEGMENTS_CACHE[name] ||= name.split(SEPARATOR).freeze
end
# --

0 comments on commit dde6ac7

Please sign in to comment.