Last active
December 31, 2015 17:49
-
-
Save tomjnixon/8022782 to your computer and use it in GitHub Desktop.
Benchmark for SPARQL results parsing.
This file contains hidden or 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
require 'sparql/client' | |
require 'benchmark' | |
def generate(n) | |
parts = [] | |
parts << '<?xml version="1.0"?> | |
<sparql xmlns="http://www.w3.org/2005/sparql-results#"> | |
<head> | |
<variable name="a"/> | |
<variable name="b"/> | |
<variable name="c"/> | |
</head> | |
<results> | |
' | |
(1..n).each do |i| | |
parts << " | |
<result> | |
<binding name=\"a\"> | |
<bnode>r#{i}</bnode> | |
</binding> | |
<binding name=\"b\"> | |
<uri>http://work.example.org/foo/bar/#{i}</uri> | |
</binding> | |
<binding name=\"c\"> | |
<literal datatype=\"http://www.w3.org/2001/XMLSchema#integer\">#{i}</literal> | |
</binding> | |
</result>" | |
end | |
parts << ' | |
</results> | |
</sparql> | |
' | |
parts.join | |
end | |
# warm up | |
SPARQL::Client::parse_xml_bindings(generate(100), {}) | |
runs_per_step = 3 | |
puts "size,time" | |
(0..1000).step(10) do |n| | |
xml = generate(n) | |
t = Benchmark.realtime do | |
runs_per_step.times do | |
nodes = {} | |
SPARQL::Client::parse_xml_bindings(xml, nodes) | |
end | |
end | |
puts "#{n},#{t/runs_per_step}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment