Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 88 lines (74 sloc) 2.386 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

URLs = {
# "data/google-news.xml" => "http://news.google.com/?output=atom",
  "data/twitter-search.xml" => "http://search.twitter.com/search.atom?lang=en&q=xml&rpp=100",
# Leave out Twitter timeline for now, as we can build benchmarks
# around assumption of atom-formatted documents
# "data/twitter-timeline.xml" => "http://twitter.com/statuses/public_timeline.xml"
}

$LOAD_PATH << "./lib"
require 'xmlbench/harness'
require 'open-uri'

directory "data"

rule ".xml" => "data" do |t|
  fail "Don't know URL where I can fetch #{t.name}!" unless URLs[t.name]
  File.open(t.name, "w") do |f|
    open(URLs[t.name]) do |url|
      f << url.read
    end
  end
end

desc "Clean cached data and any output files"
task :clean do
  rm_f URLs.keys
end

def check_objectspace
  if defined?(JRUBY_VERSION)
    require 'jruby'
    fail "Re-run JRuby with -X+O to enable ObjectSpace (needed for Nokogiri)" unless JRuby.objectspace
  end
end

desc "Fetch new data"
task :check_data => URLs.keys

namespace :bench do
  def run_files(paths)
    parsers = paths.map {|f| f =~ %r{(xmlbench/.*)\.rb} && $1 }
    Harness.run_parsers(parsers, URLs.keys.sort, ENV['N'] && ENV['N'].to_i)
  rescue => e
    puts e.message
    if e.message =~ /undefined method/
      check_objectspace
    else
      raise
    end
  end

  desc "Run the benchmarks on all parsers."
  task :all => :check_data do
    run_files(FileList['lib/xmlbench/*/**/*.rb'])
  end

  Dir['lib/xmlbench/*'].each do |dir|
    if File.directory?(dir)
      basename = File.basename(dir)
      desc "Run the #{basename} parser benchmarks."
      task basename => :check_data do
        run_files(FileList["#{dir}/**/*.rb"])
      end
    end
  end
end

task :bench => :check_data do
  fail "specify parser with PARSERS=lib/xmlbench/somefile.rb" unless ENV["BENCH"]
  run_files(FileList[*(ENV["BENCH"].split(/\s*,\s*/))])
end

require 'spec/rake/spectask'
Spec::Rake::SpecTask.new do |t|
  t.ruby_opts = ['-Ilib', '-rubygems']
  t.ruby_opts.unshift "-X+O" if defined?(JRUBY_VERSION) # enable objectspace; needed for nokogiri
  t.spec_files = FileList["spec/**/*_spec.rb"]
end

task :default do
  puts "XML Parser benchmarks. Available tasks:"
  Rake.application.options.show_tasks = true
  Rake.application.options.full_description = false
  Rake.application.options.show_task_pattern = //
  Rake.application.display_tasks_and_comments
end
Something went wrong with that request. Please try again.