-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I want to improve the parsing process and would like to add a parsing benchmark. The benchmark process just parses the XML from beginning to end. Since performance differs depending on whether YJIT is ON or OFF, both are measured.
- Loading branch information
Showing
4 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Benchmark | ||
|
||
on: | ||
- push | ||
- pull_request | ||
|
||
jobs: | ||
benchmark: | ||
name: "Benchmark: Ruby ${{ matrix.ruby-version }}: ${{ matrix.runs-on }}" | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
ruby-version: | ||
- '3.3' | ||
runs-on: | ||
- ubuntu-latest | ||
runs-on: ${{ matrix.runs-on }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: ${{ matrix.ruby-version }} | ||
- name: Install dependencies | ||
run: | | ||
bundle install | ||
gem install rexml -v 3.2.6 | ||
- name: Benchmark | ||
run: | | ||
rake benchmark |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
loop_count: 100 | ||
contexts: | ||
- gems: | ||
rexml: 3.2.6 | ||
require: false | ||
prelude: require 'rexml' | ||
- name: master | ||
prelude: | | ||
$LOAD_PATH.unshift(File.expand_path("lib")) | ||
require 'rexml' | ||
- name: 3.2.6(YJIT) | ||
gems: | ||
rexml: 3.2.6 | ||
require: false | ||
prelude: | | ||
require 'rexml' | ||
RubyVM::YJIT.enable | ||
- name: master(YJIT) | ||
prelude: | | ||
$LOAD_PATH.unshift(File.expand_path("lib")) | ||
require 'rexml' | ||
RubyVM::YJIT.enable | ||
prelude: | | ||
require 'rexml/document' | ||
require 'rexml/parsers/sax2parser' | ||
require 'rexml/parsers/pullparser' | ||
require 'rexml/parsers/streamparser' | ||
require 'rexml/streamlistener' | ||
n_elements = Integer(ENV.fetch("N_ELEMENTS", "5000"), 10) | ||
n_attributes = Integer(ENV.fetch("N_ATTRIBUTES", "2"), 10) | ||
def build_xml(n_elements, n_attributes) | ||
xml = '<?xml version="1.0"?><root>' | ||
n_elements.times do |i| | ||
xml << '<child ' | ||
n_attributes.times {|j| xml << "id#{j}=\"#{i}\" " } | ||
xml << '/>' | ||
end | ||
xml << '</root>' | ||
end | ||
xml = build_xml(n_elements, n_attributes) | ||
class Listener | ||
include REXML::StreamListener | ||
end | ||
benchmark: | ||
'dom' : REXML::Document.new(xml).elements.each("root/child") {|_|} | ||
'sax' : REXML::Parsers::SAX2Parser.new(xml).parse | ||
'pull' : | | ||
parser = REXML::Parsers::PullParser.new(xml) | ||
while parser.has_next? | ||
parser.pull | ||
end | ||
'stream' : REXML::Parsers::StreamParser.new(xml, Listener.new).parse |
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