Skip to content

Instantly share code, notes, and snippets.

@yorickpeterse
Created April 17, 2014 15:47
Show Gist options
  • Save yorickpeterse/afa7db82d9f1530800ae to your computer and use it in GitHub Desktop.
Save yorickpeterse/afa7db82d9f1530800ae to your computer and use it in GitHub Desktop.
# Slap this in the root of the cloned repository (or change the require relative).
require 'progress_bar'
require_relative 'lib/oga'
def memory_usage
`ps -o rss= #{Process.pid}`.strip.to_f
end
puts 'Reading XML...'
# XML downloaded from http://www.ins.cwi.nl/projects/xmark/Assets/standard.gz
# Adjust path to it if needed (probably)
xml = File.read('/home/yorickpeterse/Downloads/big.xml')
start_mem = memory_usage
start_time = Time.now.to_i
newline = "\n"
progress = ProgressBar.new(2035122) # from wc -l because lazy
lexer = Oga::XML::Lexer.new(xml)
puts 'Lexing XML...'
lexer.advance do |token|
progress.increment! if token[1] == newline
end
diff_mb = ((memory_usage - start_mem) / 1024).round(2)
diff_time = Time.now.to_i - start_time
puts "Usage: #{diff_mb} MB"
puts "Time: #{diff_time} sec"
git clone git@github.com:YorickPeterse/oga.git
cd oga
bundle install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment