summaryrefslogtreecommitdiff
path: root/spec/ruby/core/array/pack
diff options
context:
space:
mode:
authorWatson <watson1978@gmail.com>2018-03-02 00:33:18 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-10-14 19:54:49 +0900
commita2f9c38a718eecef6795b4a8667589c0ef68b737 (patch)
tree667d2f96ea03655fcdab9eda45ed4a7c11fe2cdb /spec/ruby/core/array/pack
parent2003755a2c491fd81496308cad97ce6304c51fe8 (diff)
[flori/json] Convert Hash object using rb_hash_foreach()
To convert Hash convert, this part was using following pseudo code ``` obj.keys.each do |key| value = obj[key] ... end ``` and `rb_funcall()` was called for `obj.keys`. It might be slightly heavy to call the Ruby method. This patch will iterate to convert Hash object about key/value using `rb_hash_foreach()` Ruby API instead of `rb_funcall()`. ``` $ ruby bench_json_generate.rb Warming up -------------------------------------- json 55.000 i/100ms Calculating ------------------------------------- json 558.501 (± 1.1%) i/s - 2.805k in 5.022986s ``` ``` $ ruby bench_json_generate.rb Warming up -------------------------------------- json 65.000 i/100ms Calculating ------------------------------------- json 659.576 (± 1.5%) i/s - 3.315k in 5.027127s ``` ``` require 'json' require 'benchmark/ips' obj = [] 1000.times do |i| obj << { "id" => i, :age => 42, } end Benchmark.ips do |x| x.report "json" do |iter| count = 0 while count < iter JSON.generate(obj) count += 1 end end end ``` https://github.com/flori/json/commit/a73323dc5e
Diffstat (limited to 'spec/ruby/core/array/pack')
0 files changed, 0 insertions, 0 deletions