``` $ make benchmark ITEM=nilclass COMPARE_RUBY="/opt/rubies/ruby-master/bin/ruby" /opt/rubies/3.4.2/bin/ruby --disable=gems -rrubygems -I../benchmark/lib ../benchmark/benchmark-driver/exe/benchmark-driver \ --executables="compare-ruby::/opt/rubies/ruby-master/bin/ruby -I.ext/common --disable-gem" \ --executables="built-ruby::./miniruby -I../lib -I. -I.ext/common ../tool/runruby.rb --extout=.ext -- --disable-gems --disable-gem" \ --output=markdown --output-compare -v $(find ../benchmark -maxdepth 1 -name 'nilclass' -o -name '*nilclass*.yml' -o -name '*nilclass*.rb' | sort) compare-ruby: ruby 3.5.0dev (2025-06-02T13:52:25Z master cbd49ecbbe) +PRISM [arm64-darwin24] built-ruby: ruby 3.5.0dev (2025-06-02T22:47:21Z hm-ruby-nilclass 3e7f1f0466) +PRISM [arm64-darwin24] | |compare-ruby|built-ruby| |:------------|-----------:|---------:| |rationalize | 24.056M| 53.908M| | | -| 2.24x| |to_c | 23.652M| 82.781M| | | -| 3.50x| |to_i | 89.526M| 84.388M| | | 1.06x| -| |to_f | 84.746M| 96.899M| | | -| 1.14x| |to_r | 25.107M| 83.472M| | | -| 3.32x| |splat | 42.772M| 42.717M| | | 1.00x| -| ``` This makes them much faster
64 lines
798 B
Ruby
64 lines
798 B
Ruby
class NilClass
|
|
#
|
|
# call-seq:
|
|
# rationalize(eps = nil) -> (0/1)
|
|
#
|
|
# Returns zero as a Rational:
|
|
#
|
|
# nil.rationalize # => (0/1)
|
|
#
|
|
# Argument +eps+ is ignored.
|
|
#
|
|
def rationalize(eps = nil)
|
|
0r
|
|
end
|
|
|
|
#
|
|
# call-seq:
|
|
# to_c -> (0+0i)
|
|
#
|
|
# Returns zero as a Complex:
|
|
#
|
|
# nil.to_c # => (0+0i)
|
|
#
|
|
def to_c
|
|
0i
|
|
end
|
|
|
|
#
|
|
# call-seq:
|
|
# nil.to_i -> 0
|
|
#
|
|
# Always returns zero.
|
|
#
|
|
# nil.to_i #=> 0
|
|
#
|
|
def to_i
|
|
return 0
|
|
end
|
|
|
|
#
|
|
# call-seq:
|
|
# nil.to_f -> 0.0
|
|
#
|
|
# Always returns zero.
|
|
#
|
|
# nil.to_f #=> 0.0
|
|
#
|
|
def to_f
|
|
return 0.0
|
|
end
|
|
|
|
#
|
|
# call-seq:
|
|
# to_r -> (0/1)
|
|
#
|
|
# Returns zero as a Rational:
|
|
#
|
|
# nil.to_r # => (0/1)
|
|
#
|
|
def to_r
|
|
0r
|
|
end
|
|
end
|