Project

General

Profile

« Previous | Next » 

Revision cb3e6251

Added by watson1978 (Shizuo Fujita) almost 5 years ago

[flori/json] Use frozen string for hash key

When use non-frozen string for hash key with rb_hash_aset(), it will duplicate and freeze it internally.
To avoid duplicate and freeze, this patch will give a frozen string in rb_hash_aset().

Warming up --------------------------------------
                json    14.000  i/100ms
Calculating -------------------------------------
                json    148.844  (± 1.3%) i/s -    756.000  in   5.079969s
Warming up --------------------------------------
                json    16.000  i/100ms
Calculating -------------------------------------
                json    165.608  (± 1.8%) i/s -    832.000  in   5.025367s
require 'json'
require 'securerandom'
require 'benchmark/ips'

obj = []

1000.times do |i|
  obj << {
    "id": i,
    "uuid": SecureRandom.uuid,
    "created_at": Time.now
  }
end

json = obj.to_json

Benchmark.ips do |x|
  x.report "json" do |iter|
    count = 0
    while count < iter
      JSON.parse(json)
      count += 1
    end
  end
end

https://github.com/flori/json/commit/18292c0c1d