diff options
author | Watson <watson1978@gmail.com> | 2018-03-02 00:51:30 +0900 |
---|---|---|
committer | Florian Frank <flori@ping.de> | 2019-04-29 15:58:28 +0200 |
commit | 9ae6d2969cb1e3b927897806e5b632cb2912a0b6 (patch) | |
tree | 5c1b20b5a7b111e93e3b9dc033d3435be7244729 /java/src/json/ext/Parser.java | |
parent | 38c0f6dbe4d6709988eecd6b04c59a48066de876 (diff) | |
download | json-9ae6d2969cb1e3b927897806e5b632cb2912a0b6.tar.gz |
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
```
Diffstat (limited to 'java/src/json/ext/Parser.java')
0 files changed, 0 insertions, 0 deletions