Skip to content

Instantly share code, notes, and snippets.

@szimek
Created June 20, 2009 17:04
Show Gist options
  • Save szimek/3d3270abf62370317809 to your computer and use it in GitHub Desktop.
Save szimek/3d3270abf62370317809 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'builder'
def xml_proc
Proc.new do |b|
b.node do |b|
2500.times {b.inner_node "some fake data"}
end
end
end
File.open('short_sample.xml', 'w') do |file|
b = Builder::XmlMarkup.new(:target => file, :indent => 2)
b.nodes {|b| xml_proc.call(b)}
end
File.open('long_sample.xml', 'w') do |file|
b = Builder::XmlMarkup.new(:target => file, :indent => 2)
b.nodes {|b| 1000.times { xml_proc.call(b) } }
end
require 'rubygems'
gem 'libxml-ruby', '>= 1.1.3'
require 'xml/libxml'
def parse
x = XML::Reader.file('long_sample.xml', :options => XML::Parser::Options::NOBLANKS)
x.next # <nodes>
x.read # first <node>
begin
x.expand
GC.start
end while x.next != 0
x.close
end
parse
require 'rubygems'
gem 'libxml-ruby', '>= 1.1.3'
require 'xml/libxml'
def parse
x = XML::Reader.file('short_sample.xml', :options => XML::Parser::Options::NOBLANKS)
x.next # <nodes>
x.read # first <node>
begin
x.expand
GC.start
end while x.next != 0
x.close
end
1000.times {parse}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment