mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
4ba3a4491e
This improve the conversion speed several times faster than before.
```
RUBYLIB= BUNDLER_ORIG_RUBYLIB= /home/mrkn/.rbenv/versions/3.0.0/bin/ruby -v -S benchmark-driver /home/mrkn/src/github.com/ruby/bigdecimal/benchmark/from_float.yml
ruby 3.0.0p0 (2020-12-25 revision 95aff21468
) [x86_64-linux]
Calculating -------------------------------------
bigdecimal 3.0.0 master
flt_e0 156.400k 783.356k i/s - 100.000k times in 0.639388s 0.127656s
flt_ep10 158.640k 777.978k i/s - 100.000k times in 0.630359s 0.128538s
flt_ep100 101.676k 504.259k i/s - 100.000k times in 0.983512s 0.198311s
flt_em10 103.439k 726.339k i/s - 100.000k times in 0.966751s 0.137677s
flt_em100 79.675k 651.446k i/s - 100.000k times in 1.255095s 0.153505s
Comparison:
flt_e0
master: 783355.6 i/s
bigdecimal 3.0.0: 156399.5 i/s - 5.01x slower
flt_ep10
master: 777977.6 i/s
bigdecimal 3.0.0: 158639.7 i/s - 4.90x slower
flt_ep100
master: 504259.4 i/s
bigdecimal 3.0.0: 101676.5 i/s - 4.96x slower
flt_em10
master: 726338.6 i/s
bigdecimal 3.0.0: 103439.2 i/s - 7.02x slower
flt_em100
master: 651446.3 i/s
bigdecimal 3.0.0: 79675.3 i/s - 8.18x slower
```
https://github.com/ruby/bigdecimal/commit/5bdaedd530
https://github.com/ruby/bigdecimal/commit/9bfff57f90
https://github.com/ruby/bigdecimal/commit/d071a0abbb
94 lines
2.7 KiB
Ruby
94 lines
2.7 KiB
Ruby
# frozen_string_literal: false
|
|
require 'mkmf'
|
|
|
|
def check_bigdecimal_version(gemspec_path)
|
|
message "checking RUBY_BIGDECIMAL_VERSION... "
|
|
|
|
bigdecimal_version =
|
|
IO.readlines(gemspec_path)
|
|
.grep(/\Abigdecimal_version\s+=\s+/)[0][/\'([^\']+)\'/, 1]
|
|
|
|
version_components = bigdecimal_version.split('.')
|
|
bigdecimal_version = version_components[0, 3].join('.')
|
|
bigdecimal_version << "-#{version_components[3]}" if version_components[3]
|
|
$defs << %Q[-DRUBY_BIGDECIMAL_VERSION=\\"#{bigdecimal_version}\\"]
|
|
|
|
message "#{bigdecimal_version}\n"
|
|
end
|
|
|
|
def have_builtin_func(name, check_expr, opt = "", &b)
|
|
checking_for checking_message(name.funcall_style, nil, opt) do
|
|
if try_compile(<<SRC, opt, &b)
|
|
int foo;
|
|
int main() { #{check_expr}; return 0; }
|
|
SRC
|
|
$defs.push(format("-DHAVE_BUILTIN_%s", name.tr_cpp))
|
|
true
|
|
else
|
|
false
|
|
end
|
|
end
|
|
end
|
|
|
|
gemspec_name = gemspec_path = nil
|
|
unless ['', '../../'].any? {|dir|
|
|
gemspec_name = "#{dir}bigdecimal.gemspec"
|
|
gemspec_path = File.expand_path("../#{gemspec_name}", __FILE__)
|
|
File.file?(gemspec_path)
|
|
}
|
|
$stderr.puts "Unable to find bigdecimal.gemspec"
|
|
abort
|
|
end
|
|
|
|
check_bigdecimal_version(gemspec_path)
|
|
|
|
have_builtin_func("__builtin_clz", "__builtin_clz(0)")
|
|
have_builtin_func("__builtin_clzl", "__builtin_clzl(0)")
|
|
have_builtin_func("__builtin_clzll", "__builtin_clzll(0)")
|
|
|
|
have_header("float.h")
|
|
have_header("math.h")
|
|
have_header("stdbool.h")
|
|
have_header("stdlib.h")
|
|
|
|
have_header("x86intrin.h")
|
|
have_func("_lzcnt_u32", "x86intrin.h")
|
|
have_func("_lzcnt_u64", "x86intrin.h")
|
|
|
|
have_header("intrin.h")
|
|
have_func("__lzcnt", "intrin.h")
|
|
have_func("__lzcnt64", "intrin.h")
|
|
have_func("_BitScanReverse", "intrin.h")
|
|
have_func("_BitScanReverse64", "intrin.h")
|
|
|
|
have_func("labs", "stdlib.h")
|
|
have_func("llabs", "stdlib.h")
|
|
have_func("finite", "math.h")
|
|
have_func("isfinite", "math.h")
|
|
|
|
have_header("ruby/atomic.h")
|
|
have_header("ruby/internal/has/builtin.h")
|
|
have_header("ruby/internal/static_assert.h")
|
|
|
|
have_type("struct RRational", "ruby.h")
|
|
have_func("rb_rational_num", "ruby.h")
|
|
have_func("rb_rational_den", "ruby.h")
|
|
have_type("struct RComplex", "ruby.h")
|
|
have_func("rb_complex_real", "ruby.h")
|
|
have_func("rb_complex_imag", "ruby.h")
|
|
have_func("rb_array_const_ptr", "ruby.h")
|
|
have_func("rb_sym2str", "ruby.h")
|
|
have_func("rb_opts_exception_p", "ruby.h")
|
|
have_func("rb_category_warn", "ruby.h")
|
|
have_const("RB_WARN_CATEGORY_DEPRECATED", "ruby.h")
|
|
|
|
if File.file?(File.expand_path('../lib/bigdecimal.rb', __FILE__))
|
|
bigdecimal_rb = "$(srcdir)/lib/bigdecimal.rb"
|
|
else
|
|
bigdecimal_rb = "$(srcdir)/../../lib/bigdecimal.rb"
|
|
end
|
|
|
|
create_makefile('bigdecimal') {|mf|
|
|
mf << "GEMSPEC = #{gemspec_name}\n"
|
|
mf << "BIGDECIMAL_RB = #{bigdecimal_rb}\n"
|
|
}
|