# class_vs_struct.cr
require "benchmark"
require "json"
TEXT = %({"muffin": false, "test": "Random string!", "user_id" : 1234})
class Muffin
JSON.mapping(
test: String,
muffin: Bool,
user_id: Int32,
)
end
Benchmark.ips do |x|
x.report("json parse") {
json = JSON.parse(TEXT).as_h
if json["muffin"]?
end
}
x.report("from json") {
json = Muffin.from_json(TEXT)
if json.muffin
end
}
end