Project

General

Profile

Actions

Feature #17416

open

Improve performance Kernel#itself

Added by S_H_ (Shun Hiraoka) almost 4 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:101586]

Description

Improve performance Kernel#itself with Ruby code.

like this.

module Kernel
  #
  #  call-seq:
  #     obj.itself    -> obj
  #
  #  Returns the receiver.
  #
  #     string = "my string"
  #     string.itself.object_id == string.object_id   #=> true
  #
  #
  def itself
    return self
  end
end

benchmark:

prelude: |
  obj = Object.new
  ary = Array.new
  str = String.new
  int = 42
  flt = 4.2
benchmark:
  object: |
    obj.itself
  array: |
    ary.itself
  string: |
    str.itself
  integer: |
    int.itself
  float: |
    flt.itself
loop_count: 20000000

benchmark result:

sh@MyComputer:~/rubydev/build$ make benchmark/benchmark.yml -e COMPARE_RUBY=~/.rbenv/shims/ruby -e BENCH_RUBY=../install/bin/ruby
# Iteration per second (i/s)

|         |compare-ruby|built-ruby|
|:--------|-----------:|---------:|
|object   |     58.924M|   70.285M|
|         |           -|     1.19x|
|array    |     56.428M|   65.275M|
|         |           -|     1.16x|
|string   |     50.311M|   63.087M|
|         |           -|     1.25x|
|integer  |     54.838M|   62.510M|
|         |           -|     1.14x|
|float    |     56.372M|   65.399M|
|         |           -|     1.16x|

COMPARE_RUBY is ruby 3.0.0dev (2020-12-21T09:17:45Z master d84dd66da0) [x86_64-linux]. BENCH_RUBY is ahead of ruby 3.0.0dev (2020-12-21T09:17:45Z master d84dd66da0) [x86_64-linux].

No data to display

Actions

Also available in: Atom PDF

Like0