Skip to content

Instantly share code, notes, and snippets.

@ganmacs
Last active February 16, 2022 05:31
Show Gist options
  • Save ganmacs/29f6217bbd3658d7f1f0010d0cadedd7 to your computer and use it in GitHub Desktop.
Save ganmacs/29f6217bbd3658d7f1f0010d0cadedd7 to your computer and use it in GitHub Desktop.
require 'json-schema'
require 'benchmark'
schema = YAML.load_file(File.open("rule.yml")).freeze
validator = JSON::Validator.new(schema)
body = ....
Benchmark.bm do |x|
x.report("before 100") { 100.times { JSON::Validator.validate(schema, data) } }
x.report("before 1000") { 1000.times { JSON::Validator.validate(schema, data) } }
x.report("before 5000") { 5000.times { JSON::Validator.validate(schema, data) } }
x.report("after 100") { 100.times { validator.validate(data) } }
x.report("after 1000") { 1000.times { validator.validate(data) } }
x.report("after 5000") { 5000.times { validator.validate(data) } }
end
require 'json-schema'
require 'stackprof'
body = ....
schema = YAML.load_file(File.open("rule.yml")).freeze
StackProf.run(mode: :cpu, out: 'stackprof.dump', raw: true) do
100.times { JSON::Validator.validate(schema, body) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment