1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/ext/json
Watson 40724d7d10
[flori/json] Convert String encoding using rb_str_encode()
`rb_funcall` might be slightly heavy to call the Ruby method.
This patch will convert String encoding using `rb_str_encode()` instead of `rb_funcall()`.

## Before
```
$ ruby bench_json_generate.rb
Warming up --------------------------------------
                json    78.000  i/100ms
Calculating -------------------------------------
                json    789.781  (± 2.7%) i/s -      3.978k in   5.041043s
```

## After
```
$ ruby bench_json_generate.rb
Warming up --------------------------------------
                json   129.000  i/100ms
Calculating -------------------------------------
                json      1.300k (± 2.3%) i/s -      6.579k in   5.064656s
```

## Code
```
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/9ae6d2969c
2019-10-14 19:54:48 +09:00
..
fbuffer
generator [flori/json] Convert String encoding using rb_str_encode() 2019-10-14 19:54:48 +09:00
lib [flori/json] Pass args all #to_json in json/add/*. 2019-10-14 19:54:48 +09:00
parser [flori/json] Only attempt to resize strings not other objects 2019-10-14 19:54:48 +09:00
depend Added depend files 2019-07-14 01:31:29 +09:00
extconf.rb
json.gemspec Removed useless freezes from gemspec files 2019-07-13 07:25:54 +09:00