Skip to content

Instantly share code, notes, and snippets.

@no-reply
Last active Feb 27, 2016
Embed
What would you like to do?
require 'rdf/turtle'
require 'json/ld'
g = RDF::Graph.load('http://json-ld.org/test-suite/reports/ruby-earl.ttl')
File.open('ruby-earl.json', 'w') { |file| file.write(g.dump(:jsonld, standard_prefixes: true)) }
File.open('ruby-earl.nt', 'w') { |file| file.write(g.dump(:ntriples)) }
# With Defoult JSON Parser
RUBY_VERSION # => "2.1.0"
require 'json/ld'
require 'benchmark'
puts Benchmark.bmbm { |bm| bm.report { JSON::LD::API.toRdf(File.open('ruby-earl.json')) } }
# Rehearsal ------------------------------------
# 0.480000 0.030000 0.510000 ( 0.520427)
# --------------------------- total: 0.510000sec
#
# user system total real
# 0.420000 0.000000 0.420000 ( 0.425897)
# 0.420000 0.000000 0.420000 ( 0.425897)
JSON::LD::API.toRdf(File.open('ruby-earl.json')).count # => 3642
# With OJ
RUBY_VERSION # => "2.1.0"
require 'oj'
require 'json/ld'
require 'benchmark'
puts Benchmark.bmbm { |bm| bm.report { JSON::LD::API.toRdf(File.open('ruby-earl.json')) } }
# Rehearsal ------------------------------------
# 0.470000 0.020000 0.490000 ( 0.490904)
# --------------------------- total: 0.490000sec
#
# user system total real
# 0.410000 0.000000 0.410000 ( 0.418465)
# 0.410000 0.000000 0.410000 ( 0.418465)
JSON::LD::API.toRdf(File.open('ruby-earl.json')).count # => 3642
# For NTriples
require 'rdf/ntriples'
require 'benchmark'
Benchmark.bmbm { |bm| bm.report { RDF::Reader.open('ruby-earl.nt').count } }
# Rehearsal ------------------------------------
# 0.370000 0.010000 0.380000 ( 0.374357)
# --------------------------- total: 0.380000sec
#
# user system total real
# 0.370000 0.000000 0.370000 ( 0.369633)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment