Project

General

Profile

Feature #17670

Updated by S_H_ (Shun Hiraoka) about 3 years ago

 
 Improve performance `Float#to_i` and `Float#to_int` methods(write in Ruby) 

 benchmark: 
 ```yml 
 prelude: | 
   flo = 4.2 
 benchmark: 
   to_i: | 
     flo.to_i 
   to_int: | 
     flo.to_int 
 loop_count: 20000000 

 ``` 

 result: 
 ```bash 
 sh@DESKTOP-L0NI312:~/rubydev/build$ make benchmark/benchmark.yml -e COMPARE_RUBY=~/.rbenv/shims/ruby -e BENCH_RUBY=../install/bin/ruby 
 generating vm_call_iseq_optimized.inc 
 vm_call_iseq_optimized.inc unchanged 
 compare-ruby: ruby 3.1.0dev (2021-02-28T11:24:42Z master 80e2c45f55) [x86_64-linux] 
 built-ruby: ruby 3.1.0dev (2021-02-28T11:24:42Z improve_float_to_i master 80e2c45f55) [x86_64-linux] 
 # Iteration per second (i/s) 

 |          |compare-ruby|built-ruby| 
 |:-------|-----------:|---------:| 
 |to_i      |       69.184M| 66.872M|     78.294M| 75.080M| 
 |          |             -|       1.13x| 1.12x| 
 |to_int    |       69.891M| 65.597M|     80.285M| 75.298M| 
 |          |             -|       1.15x| 
 ``` 

 `COMPARE_RUBY` is `ruby 3.1.0dev (2021-02-28T11:24:42Z master 80e2c45f55) [x86_64-linux]`. `BENCH_RUBY` is ahead of `ruby 3.1.0dev (2021-02-28T11:24:42Z master 80e2c45f55) [x86_64-linux]`.

Back