[ 
https://issues.apache.org/jira/browse/SOLR-122?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12468433
 ] 

Coda Hale commented on SOLR-122:
--------------------------------

Yonik -- in this case, libxml-ruby is faster at generating XML than simple 
string concatenation in Ruby when you take the overhead of escaping into 
consideration. Anything is faster than REXML, including guessing.

====

                            user     system      total        real
string concatenation:  35.280000   0.180000  35.460000 ( 35.713158)
string substitution:   34.870000   0.180000  35.050000 ( 35.273428)
REXML:                129.480000   0.610000 130.090000 (130.845760)
libxml:                23.020000   0.130000  23.150000 ( 23.315077)

====

require "benchmark"
require "rexml/document"
require "xml/libxml"

TESTS = 1_000_000

Benchmark.bmbm do |results|
  results.report("string concatenation:") do
    TESTS.times do
      x = "<blah>"
      x << "woot".gsub("&", "&amp;").gsub("<", "&lt;").gsub(">", "&gt;")
      x << "</blah>"
    end
  end
  
  results.report("string substitution:") do
    TESTS.times do
      x = "<blah>#{"woot".gsub("&", "&amp;").gsub("<", "&lt;").gsub(">", 
"&gt;")}</blah>"
    end
  end
  
  results.report("REXML:") do
    TESTS.times do
      e = REXML::Element.new("blah")
      e.add_text("woot")
      e.to_s
    end
  end
  
  results.report("libxml:") do
    TESTS.times do
      e = XML::Node.new("blah")
      e << "woot"
      e.to_s
    end
  end
end

> Add optional support for Ruby-libxml2 (vs. REXML)
> -------------------------------------------------
>
>                 Key: SOLR-122
>                 URL: https://issues.apache.org/jira/browse/SOLR-122
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - ruby - flare
>            Reporter: Coda Hale
>         Attachments: libxml.rb, libxml.rb
>
>
> This file adds drop-in support for the ruby-libxml2, which is a wrapper for 
> the libxml2 library, which is an order of magnitude or so faster than REXML.
> This depends on my SOLR-121 patch for multi-document adds, since the behavior 
> of Solr::Request::AddDocument#to_s is different.
> Requiring this makes some tests fail, but for trivial reasons: some tests are 
> directly tied to REXML, others fail due to interelement whitespace added by 
> libxml2 (which you can't disable via the Ruby interface). Functionally, it's 
> identical, and passes all functional tests.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to