-
-
Save yorickpeterse/afa7db82d9f1530800ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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