Skip to content

Instantly share code, notes, and snippets.

@SpringMT
Created January 23, 2015 16:20
Show Gist options
  • Save SpringMT/6313458116b73556d417 to your computer and use it in GitHub Desktop.
Save SpringMT/6313458116b73556d417 to your computer and use it in GitHub Desktop.
JSON::Validator.validate遅い。。。
require 'json'
require 'json-schema'
json_data = []
70_000.times do |i|
json_data << {id: i, name: "てすとてすと", point: 20495, description: "しらたま"}
end
json_schema = <<JSON
{
"type": "array",
"items": {
"type": "object",
"required": [
"id"
],
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string",
"minLength": 2,
"maxLength": 15
},
"point": {
"type": "integer"
},
"description": {
"type": "string",
"minLength": 2,
"maxLength": 15
}
}
}
}
JSON
JSON::Validator.validate!(JSON.parse(json_schema), JSON.parse(json_data.to_json))
@SpringMT
Copy link
Author

% time bundle exec ruby sample_json.rb
bundle exec ruby sample_json.rb  5.06s user 0.28s system 90% cpu 5.914 total

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment