Project

General

Profile

Actions

Feature #17670

open

Improve performance Float#to_i

Added by S_H_ (Shun Hiraoka) 8 months ago. Updated 8 months ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:102715]

Description

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

benchmark:

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

result:

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 80e2c45f55) [x86_64-linux]
# Iteration per second (i/s)

|        |compare-ruby|built-ruby|
|:-------|-----------:|---------:|
|to_i    |     69.184M|   78.294M|
|        |           -|     1.13x|
|to_int  |     69.891M|   80.285M|
|        |           -|     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].

pull request: https://github.com/ruby/ruby/pull/4234

Actions

Also available in: Atom PDF