Skip to content

Instantly share code, notes, and snippets.

@no-reply
Last active February 27, 2016 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save no-reply/de7e002c37f7af2ed168 to your computer and use it in GitHub Desktop.
Save no-reply/de7e002c37f7af2ed168 to your computer and use it in GitHub Desktop.
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