steep 0.16.0 → 0.16.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +0 -3
- data/CHANGELOG.md +6 -0
- data/Rakefile +0 -13
- data/bin/setup +0 -2
- data/bin/smoke_runner.rb +0 -1
- data/exe/steep +0 -1
- data/lib/steep/project/file.rb +1 -1
- data/lib/steep/project/hover_content.rb +1 -1
- data/lib/steep/server/code_worker.rb +1 -1
- data/lib/steep/server/signature_worker.rb +4 -4
- data/lib/steep/type_construction.rb +10 -16
- data/lib/steep/type_inference/constant_env.rb +2 -10
- data/lib/steep/type_inference/context.rb +1 -0
- data/lib/steep/version.rb +1 -1
- data/steep.gemspec +1 -5
- metadata +17 -135
- data/exe/rbs +0 -3
- data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
- data/vendor/ruby-signature/.gitignore +0 -12
- data/vendor/ruby-signature/.rubocop.yml +0 -15
- data/vendor/ruby-signature/BSDL +0 -22
- data/vendor/ruby-signature/COPYING +0 -56
- data/vendor/ruby-signature/Gemfile +0 -6
- data/vendor/ruby-signature/README.md +0 -93
- data/vendor/ruby-signature/Rakefile +0 -142
- data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -157
- data/vendor/ruby-signature/bin/console +0 -14
- data/vendor/ruby-signature/bin/query-rdoc +0 -103
- data/vendor/ruby-signature/bin/setup +0 -10
- data/vendor/ruby-signature/bin/sort +0 -89
- data/vendor/ruby-signature/bin/test_runner.rb +0 -16
- data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
- data/vendor/ruby-signature/docs/sigs.md +0 -148
- data/vendor/ruby-signature/docs/stdlib.md +0 -152
- data/vendor/ruby-signature/docs/syntax.md +0 -528
- data/vendor/ruby-signature/exe/rbs +0 -7
- data/vendor/ruby-signature/lib/rbs.rb +0 -64
- data/vendor/ruby-signature/lib/rbs/ast/annotation.rb +0 -27
- data/vendor/ruby-signature/lib/rbs/ast/comment.rb +0 -27
- data/vendor/ruby-signature/lib/rbs/ast/declarations.rb +0 -395
- data/vendor/ruby-signature/lib/rbs/ast/members.rb +0 -362
- data/vendor/ruby-signature/lib/rbs/buffer.rb +0 -50
- data/vendor/ruby-signature/lib/rbs/builtin_names.rb +0 -55
- data/vendor/ruby-signature/lib/rbs/cli.rb +0 -558
- data/vendor/ruby-signature/lib/rbs/constant.rb +0 -26
- data/vendor/ruby-signature/lib/rbs/constant_table.rb +0 -150
- data/vendor/ruby-signature/lib/rbs/definition.rb +0 -170
- data/vendor/ruby-signature/lib/rbs/definition_builder.rb +0 -919
- data/vendor/ruby-signature/lib/rbs/environment.rb +0 -281
- data/vendor/ruby-signature/lib/rbs/environment_loader.rb +0 -136
- data/vendor/ruby-signature/lib/rbs/environment_walker.rb +0 -124
- data/vendor/ruby-signature/lib/rbs/errors.rb +0 -187
- data/vendor/ruby-signature/lib/rbs/location.rb +0 -102
- data/vendor/ruby-signature/lib/rbs/method_type.rb +0 -123
- data/vendor/ruby-signature/lib/rbs/namespace.rb +0 -91
- data/vendor/ruby-signature/lib/rbs/parser.y +0 -1344
- data/vendor/ruby-signature/lib/rbs/prototype/rb.rb +0 -553
- data/vendor/ruby-signature/lib/rbs/prototype/rbi.rb +0 -587
- data/vendor/ruby-signature/lib/rbs/prototype/runtime.rb +0 -381
- data/vendor/ruby-signature/lib/rbs/substitution.rb +0 -46
- data/vendor/ruby-signature/lib/rbs/test.rb +0 -26
- data/vendor/ruby-signature/lib/rbs/test/errors.rb +0 -61
- data/vendor/ruby-signature/lib/rbs/test/hook.rb +0 -294
- data/vendor/ruby-signature/lib/rbs/test/setup.rb +0 -58
- data/vendor/ruby-signature/lib/rbs/test/spy.rb +0 -325
- data/vendor/ruby-signature/lib/rbs/test/test_helper.rb +0 -183
- data/vendor/ruby-signature/lib/rbs/test/type_check.rb +0 -254
- data/vendor/ruby-signature/lib/rbs/type_name.rb +0 -70
- data/vendor/ruby-signature/lib/rbs/types.rb +0 -936
- data/vendor/ruby-signature/lib/rbs/variance_calculator.rb +0 -138
- data/vendor/ruby-signature/lib/rbs/vendorer.rb +0 -47
- data/vendor/ruby-signature/lib/rbs/version.rb +0 -3
- data/vendor/ruby-signature/lib/rbs/writer.rb +0 -269
- data/vendor/ruby-signature/lib/ruby/signature.rb +0 -7
- data/vendor/ruby-signature/rbs.gemspec +0 -46
- data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -60
- data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -71
- data/vendor/ruby-signature/stdlib/benchmark/benchmark.rbs +0 -372
- data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
- data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
- data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
- data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -45
- data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
- data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
- data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
- data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
- data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
- data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
- data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -413
- data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -607
- data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
- data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
- data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
- data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
- data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -194
- data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
- data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
- data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
- data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -1076
- data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
- data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
- data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -243
- data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
- data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -707
- data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
- data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -576
- data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -161
- data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -271
- data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -369
- data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -185
- data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -1104
- data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
- data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
- data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
- data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -429
- data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -1227
- data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -267
- data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
- data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
- data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -57
- data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -1083
- data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
- data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
- data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -1901
- data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -284
- data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
- data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -228
- data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1108
- data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
- data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -1047
- data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -290
- data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
- data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -153
- data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
- data/vendor/ruby-signature/stdlib/coverage/coverage.rbs +0 -62
- data/vendor/ruby-signature/stdlib/csv/csv.rbs +0 -773
- data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -392
- data/vendor/ruby-signature/stdlib/find/find.rbs +0 -40
- data/vendor/ruby-signature/stdlib/ipaddr/ipaddr.rbs +0 -247
- data/vendor/ruby-signature/stdlib/json/json.rbs +0 -335
- data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -1093
- data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
- data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
- data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
- data/vendor/ruby-signature/stdlib/set/set.rbs +0 -301
- data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
@@ -1,46 +0,0 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "rbs/version"
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "rbs"
|
8
|
-
spec.version = RBS::VERSION
|
9
|
-
spec.authors = ["Soutaro Matsumoto"]
|
10
|
-
spec.email = ["matsumoto@soutaro.com"]
|
11
|
-
|
12
|
-
spec.summary = %q{Type signature for Ruby classes.}
|
13
|
-
spec.description = %q{Type signature for Ruby classes.}
|
14
|
-
spec.homepage = "https://github.com/ruby/ruby-signature"
|
15
|
-
spec.licenses = ['BSD-2-Clause', 'Ruby']
|
16
|
-
|
17
|
-
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
-
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
-
if spec.respond_to?(:metadata)
|
20
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
21
|
-
spec.metadata["source_code_uri"] = "https://github.com/ruby/ruby-signature.git"
|
22
|
-
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
23
|
-
else
|
24
|
-
raise "RubyGems 2.0 or newer is required to protect against " \
|
25
|
-
"public gem pushes."
|
26
|
-
end
|
27
|
-
|
28
|
-
# Specify which files should be added to the gem when it is released.
|
29
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
30
|
-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
31
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
32
|
-
end
|
33
|
-
spec.files << "lib/rbs/parser.rb"
|
34
|
-
spec.bindir = "exe"
|
35
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
|
-
spec.require_paths = ["lib"]
|
37
|
-
|
38
|
-
spec.add_development_dependency "bundler"
|
39
|
-
spec.add_development_dependency "rake", "~> 13.0"
|
40
|
-
spec.add_development_dependency "minitest", "~> 5.0"
|
41
|
-
spec.add_development_dependency "racc", "~> 1.4.16"
|
42
|
-
spec.add_development_dependency "rubocop"
|
43
|
-
spec.add_development_dependency "rubocop-rubycw"
|
44
|
-
spec.add_development_dependency "minitest-reporters", "~> 1.3.6"
|
45
|
-
spec.add_development_dependency "json", "~> 2.3.0"
|
46
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
# Calculates the set of unambiguous abbreviations for a given set of strings.
|
2
|
-
#
|
3
|
-
# require 'abbrev'
|
4
|
-
# require 'pp'
|
5
|
-
#
|
6
|
-
# pp Abbrev.abbrev(['ruby'])
|
7
|
-
# #=> {"ruby"=>"ruby", "rub"=>"ruby", "ru"=>"ruby", "r"=>"ruby"}
|
8
|
-
#
|
9
|
-
# pp Abbrev.abbrev(%w{ ruby rules })
|
10
|
-
#
|
11
|
-
# *Generates:*
|
12
|
-
# { "ruby" => "ruby",
|
13
|
-
# "rub" => "ruby",
|
14
|
-
# "rules" => "rules",
|
15
|
-
# "rule" => "rules",
|
16
|
-
# "rul" => "rules" }
|
17
|
-
#
|
18
|
-
# It also provides an array core extension, Array#abbrev.
|
19
|
-
#
|
20
|
-
# pp %w{ summer winter }.abbrev
|
21
|
-
#
|
22
|
-
# *Generates:*
|
23
|
-
# { "summer" => "summer",
|
24
|
-
# "summe" => "summer",
|
25
|
-
# "summ" => "summer",
|
26
|
-
# "sum" => "summer",
|
27
|
-
# "su" => "summer",
|
28
|
-
# "s" => "summer",
|
29
|
-
# "winter" => "winter",
|
30
|
-
# "winte" => "winter",
|
31
|
-
# "wint" => "winter",
|
32
|
-
# "win" => "winter",
|
33
|
-
# "wi" => "winter",
|
34
|
-
# "w" => "winter" }
|
35
|
-
#
|
36
|
-
module Abbrev
|
37
|
-
# Given a set of strings, calculate the set of unambiguous abbreviations for
|
38
|
-
# those strings, and return a hash where the keys are all the possible
|
39
|
-
# abbreviations and the values are the full strings.
|
40
|
-
#
|
41
|
-
# Thus, given `words` is "car" and "cone", the keys pointing to "car" would be
|
42
|
-
# "ca" and "car", while those pointing to "cone" would be "co", "con", and
|
43
|
-
# "cone".
|
44
|
-
#
|
45
|
-
# require 'abbrev'
|
46
|
-
#
|
47
|
-
# Abbrev.abbrev(%w{ car cone })
|
48
|
-
# #=> {"ca"=>"car", "con"=>"cone", "co"=>"cone", "car"=>"car", "cone"=>"cone"}
|
49
|
-
#
|
50
|
-
# The optional `pattern` parameter is a pattern or a string. Only input strings
|
51
|
-
# that match the pattern or start with the string are included in the output
|
52
|
-
# hash.
|
53
|
-
#
|
54
|
-
# Abbrev.abbrev(%w{car box cone crab}, /b/)
|
55
|
-
# #=> {"box"=>"box", "bo"=>"box", "b"=>"box", "crab" => "crab"}
|
56
|
-
#
|
57
|
-
# Abbrev.abbrev(%w{car box cone}, 'ca')
|
58
|
-
# #=> {"car"=>"car", "ca"=>"car"}
|
59
|
-
def self?.abbrev: (Array[String], ?String | Regexp | nil) -> Hash[String, String]
|
60
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
# The Base64 module provides for the encoding (#encode64, #strict_encode64,
|
2
|
-
# #urlsafe_encode64) and decoding (#decode64, #strict_decode64,
|
3
|
-
# #urlsafe_decode64) of binary data using a Base64 representation.
|
4
|
-
#
|
5
|
-
# ## Example
|
6
|
-
#
|
7
|
-
# A simple encoding and decoding.
|
8
|
-
#
|
9
|
-
# require "base64"
|
10
|
-
#
|
11
|
-
# enc = Base64.encode64('Send reinforcements')
|
12
|
-
# # -> "U2VuZCByZWluZm9yY2VtZW50cw==\n"
|
13
|
-
# plain = Base64.decode64(enc)
|
14
|
-
# # -> "Send reinforcements"
|
15
|
-
#
|
16
|
-
# The purpose of using base64 to encode data is that it translates any binary
|
17
|
-
# data into purely printable characters.
|
18
|
-
#
|
19
|
-
module Base64
|
20
|
-
# Returns the Base64-decoded version of `str`. This method complies with RFC
|
21
|
-
# 2045. Characters outside the base alphabet are ignored.
|
22
|
-
#
|
23
|
-
# require 'base64'
|
24
|
-
# str = 'VGhpcyBpcyBsaW5lIG9uZQpUaGlzIG' +
|
25
|
-
# 'lzIGxpbmUgdHdvClRoaXMgaXMgbGlu' +
|
26
|
-
# 'ZSB0aHJlZQpBbmQgc28gb24uLi4K'
|
27
|
-
# puts Base64.decode64(str)
|
28
|
-
#
|
29
|
-
# *Generates:*
|
30
|
-
#
|
31
|
-
# This is line one
|
32
|
-
# This is line two
|
33
|
-
# This is line three
|
34
|
-
# And so on...
|
35
|
-
def self?.decode64: (String str) -> String
|
36
|
-
|
37
|
-
# Returns the Base64-encoded version of `bin`. This method complies with RFC
|
38
|
-
# 2045. Line feeds are added to every 60 encoded characters.
|
39
|
-
#
|
40
|
-
# require 'base64'
|
41
|
-
# Base64.encode64("Now is the time for all good coders\nto learn Ruby")
|
42
|
-
#
|
43
|
-
# *Generates:*
|
44
|
-
#
|
45
|
-
# Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g
|
46
|
-
# UnVieQ==
|
47
|
-
def self?.encode64: (String bin) -> String
|
48
|
-
|
49
|
-
# Returns the Base64-decoded version of `str`. This method complies with RFC
|
50
|
-
# 4648. ArgumentError is raised if `str` is incorrectly padded or contains
|
51
|
-
# non-alphabet characters. Note that CR or LF are also rejected.
|
52
|
-
def self?.strict_decode64: (String str) -> String
|
53
|
-
|
54
|
-
# Returns the Base64-encoded version of `bin`. This method complies with RFC
|
55
|
-
# 4648. No line feeds are added.
|
56
|
-
def self?.strict_encode64: (String bin) -> String
|
57
|
-
|
58
|
-
# Returns the Base64-decoded version of `str`. This method complies with ``Base
|
59
|
-
# 64 Encoding with URL and Filename Safe Alphabet'' in RFC 4648. The alphabet
|
60
|
-
# uses '-' instead of '+' and '_' instead of '/'.
|
61
|
-
#
|
62
|
-
# The padding character is optional. This method accepts both correctly-padded
|
63
|
-
# and unpadded input. Note that it still rejects incorrectly-padded input.
|
64
|
-
def self?.urlsafe_decode64: (String str) -> String
|
65
|
-
|
66
|
-
# Returns the Base64-encoded version of `bin`. This method complies with ``Base
|
67
|
-
# 64 Encoding with URL and Filename Safe Alphabet'' in RFC 4648. The alphabet
|
68
|
-
# uses '-' instead of '+' and '_' instead of '/'. Note that the result can still
|
69
|
-
# contain '='. You can remove the padding by setting `padding` as false.
|
70
|
-
def self?.urlsafe_encode64: (String bin, ?padding: bool) -> String
|
71
|
-
end
|
@@ -1,372 +0,0 @@
|
|
1
|
-
# The Benchmark module provides methods to measure and report the time used to
|
2
|
-
# execute Ruby code.
|
3
|
-
#
|
4
|
-
# * Measure the time to construct the string given by the expression
|
5
|
-
# `"a"*1_000_000_000`:
|
6
|
-
#
|
7
|
-
# require 'benchmark'
|
8
|
-
#
|
9
|
-
# puts Benchmark.measure { "a"*1_000_000_000 }
|
10
|
-
#
|
11
|
-
# On my machine (OSX 10.8.3 on i5 1.7 GHz) this generates:
|
12
|
-
#
|
13
|
-
# 0.350000 0.400000 0.750000 ( 0.835234)
|
14
|
-
#
|
15
|
-
# This report shows the user CPU time, system CPU time, the sum of the user
|
16
|
-
# and system CPU times, and the elapsed real time. The unit of time is
|
17
|
-
# seconds.
|
18
|
-
#
|
19
|
-
# * Do some experiments sequentially using the #bm method:
|
20
|
-
#
|
21
|
-
# require 'benchmark'
|
22
|
-
#
|
23
|
-
# n = 5000000
|
24
|
-
# Benchmark.bm do |x|
|
25
|
-
# x.report { for i in 1..n; a = "1"; end }
|
26
|
-
# x.report { n.times do ; a = "1"; end }
|
27
|
-
# x.report { 1.upto(n) do ; a = "1"; end }
|
28
|
-
# end
|
29
|
-
#
|
30
|
-
# The result:
|
31
|
-
#
|
32
|
-
# user system total real
|
33
|
-
# 1.010000 0.000000 1.010000 ( 1.014479)
|
34
|
-
# 1.000000 0.000000 1.000000 ( 0.998261)
|
35
|
-
# 0.980000 0.000000 0.980000 ( 0.981335)
|
36
|
-
#
|
37
|
-
# * Continuing the previous example, put a label in each report:
|
38
|
-
#
|
39
|
-
# require 'benchmark'
|
40
|
-
#
|
41
|
-
# n = 5000000
|
42
|
-
# Benchmark.bm(7) do |x|
|
43
|
-
# x.report("for:") { for i in 1..n; a = "1"; end }
|
44
|
-
# x.report("times:") { n.times do ; a = "1"; end }
|
45
|
-
# x.report("upto:") { 1.upto(n) do ; a = "1"; end }
|
46
|
-
# end
|
47
|
-
#
|
48
|
-
#
|
49
|
-
# The result:
|
50
|
-
#
|
51
|
-
# user system total real
|
52
|
-
# for: 1.010000 0.000000 1.010000 ( 1.015688)
|
53
|
-
# times: 1.000000 0.000000 1.000000 ( 1.003611)
|
54
|
-
# upto: 1.030000 0.000000 1.030000 ( 1.028098)
|
55
|
-
#
|
56
|
-
# * The times for some benchmarks depend on the order in which items are run.
|
57
|
-
# These differences are due to the cost of memory allocation and garbage
|
58
|
-
# collection. To avoid these discrepancies, the #bmbm method is provided.
|
59
|
-
# For example, to compare ways to sort an array of floats:
|
60
|
-
#
|
61
|
-
# require 'benchmark'
|
62
|
-
#
|
63
|
-
# array = (1..1000000).map { rand }
|
64
|
-
#
|
65
|
-
# Benchmark.bmbm do |x|
|
66
|
-
# x.report("sort!") { array.dup.sort! }
|
67
|
-
# x.report("sort") { array.dup.sort }
|
68
|
-
# end
|
69
|
-
#
|
70
|
-
# The result:
|
71
|
-
#
|
72
|
-
# Rehearsal -----------------------------------------
|
73
|
-
# sort! 1.490000 0.010000 1.500000 ( 1.490520)
|
74
|
-
# sort 1.460000 0.000000 1.460000 ( 1.463025)
|
75
|
-
# -------------------------------- total: 2.960000sec
|
76
|
-
#
|
77
|
-
# user system total real
|
78
|
-
# sort! 1.460000 0.000000 1.460000 ( 1.460465)
|
79
|
-
# sort 1.450000 0.010000 1.460000 ( 1.448327)
|
80
|
-
#
|
81
|
-
# * Report statistics of sequential experiments with unique labels, using the
|
82
|
-
# #benchmark method:
|
83
|
-
#
|
84
|
-
# require 'benchmark'
|
85
|
-
# include Benchmark # we need the CAPTION and FORMAT constants
|
86
|
-
#
|
87
|
-
# n = 5000000
|
88
|
-
# Benchmark.benchmark(CAPTION, 7, FORMAT, ">total:", ">avg:") do |x|
|
89
|
-
# tf = x.report("for:") { for i in 1..n; a = "1"; end }
|
90
|
-
# tt = x.report("times:") { n.times do ; a = "1"; end }
|
91
|
-
# tu = x.report("upto:") { 1.upto(n) do ; a = "1"; end }
|
92
|
-
# [tf+tt+tu, (tf+tt+tu)/3]
|
93
|
-
# end
|
94
|
-
#
|
95
|
-
# The result:
|
96
|
-
#
|
97
|
-
# user system total real
|
98
|
-
# for: 0.950000 0.000000 0.950000 ( 0.952039)
|
99
|
-
# times: 0.980000 0.000000 0.980000 ( 0.984938)
|
100
|
-
# upto: 0.950000 0.000000 0.950000 ( 0.946787)
|
101
|
-
# >total: 2.880000 0.000000 2.880000 ( 2.883764)
|
102
|
-
# >avg: 0.960000 0.000000 0.960000 ( 0.961255)
|
103
|
-
#
|
104
|
-
#
|
105
|
-
module Benchmark
|
106
|
-
# Invokes the block with a Benchmark::Report object, which may be used to
|
107
|
-
# collect and report on the results of individual benchmark tests. Reserves
|
108
|
-
# `label_width` leading spaces for labels on each line. Prints `caption` at the
|
109
|
-
# top of the report, and uses `format` to format each line. Returns an array of
|
110
|
-
# Benchmark::Tms objects.
|
111
|
-
#
|
112
|
-
# If the block returns an array of Benchmark::Tms objects, these will be used to
|
113
|
-
# format additional lines of output. If `labels` parameter are given, these are
|
114
|
-
# used to label these extra lines.
|
115
|
-
#
|
116
|
-
# *Note*: Other methods provide a simpler interface to this one, and are
|
117
|
-
# suitable for nearly all benchmarking requirements. See the examples in
|
118
|
-
# Benchmark, and the #bm and #bmbm methods.
|
119
|
-
#
|
120
|
-
# Example:
|
121
|
-
#
|
122
|
-
# require 'benchmark'
|
123
|
-
# include Benchmark # we need the CAPTION and FORMAT constants
|
124
|
-
#
|
125
|
-
# n = 5000000
|
126
|
-
# Benchmark.benchmark(CAPTION, 7, FORMAT, ">total:", ">avg:") do |x|
|
127
|
-
# tf = x.report("for:") { for i in 1..n; a = "1"; end }
|
128
|
-
# tt = x.report("times:") { n.times do ; a = "1"; end }
|
129
|
-
# tu = x.report("upto:") { 1.upto(n) do ; a = "1"; end }
|
130
|
-
# [tf+tt+tu, (tf+tt+tu)/3]
|
131
|
-
# end
|
132
|
-
#
|
133
|
-
# Generates:
|
134
|
-
#
|
135
|
-
# user system total real
|
136
|
-
# for: 0.970000 0.000000 0.970000 ( 0.970493)
|
137
|
-
# times: 0.990000 0.000000 0.990000 ( 0.989542)
|
138
|
-
# upto: 0.970000 0.000000 0.970000 ( 0.972854)
|
139
|
-
# >total: 2.930000 0.000000 2.930000 ( 2.932889)
|
140
|
-
# >avg: 0.976667 0.000000 0.976667 ( 0.977630)
|
141
|
-
#
|
142
|
-
def self?.benchmark: (String caption, ?Integer? label_width, ?String? format, *String labels) { (Report report) -> (Array[Tms] | void) } -> ::Array[Benchmark::Tms]
|
143
|
-
|
144
|
-
# A simple interface to the #benchmark method, #bm generates sequential reports
|
145
|
-
# with labels. `label_width` and `labels` parameters have the same meaning as
|
146
|
-
# for #benchmark.
|
147
|
-
#
|
148
|
-
# require 'benchmark'
|
149
|
-
#
|
150
|
-
# n = 5000000
|
151
|
-
# Benchmark.bm(7) do |x|
|
152
|
-
# x.report("for:") { for i in 1..n; a = "1"; end }
|
153
|
-
# x.report("times:") { n.times do ; a = "1"; end }
|
154
|
-
# x.report("upto:") { 1.upto(n) do ; a = "1"; end }
|
155
|
-
# end
|
156
|
-
#
|
157
|
-
# Generates:
|
158
|
-
#
|
159
|
-
# user system total real
|
160
|
-
# for: 0.960000 0.000000 0.960000 ( 0.957966)
|
161
|
-
# times: 0.960000 0.000000 0.960000 ( 0.960423)
|
162
|
-
# upto: 0.950000 0.000000 0.950000 ( 0.954864)
|
163
|
-
#
|
164
|
-
def self?.bm: (?Integer label_width, *String labels) { (Report report) -> void } -> ::Array[Benchmark::Tms]
|
165
|
-
|
166
|
-
# Sometimes benchmark results are skewed because code executed earlier
|
167
|
-
# encounters different garbage collection overheads than that run later. #bmbm
|
168
|
-
# attempts to minimize this effect by running the tests twice, the first time as
|
169
|
-
# a rehearsal in order to get the runtime environment stable, the second time
|
170
|
-
# for real. GC.start is executed before the start of each of the real timings;
|
171
|
-
# the cost of this is not included in the timings. In reality, though, there's
|
172
|
-
# only so much that #bmbm can do, and the results are not guaranteed to be
|
173
|
-
# isolated from garbage collection and other effects.
|
174
|
-
#
|
175
|
-
# Because #bmbm takes two passes through the tests, it can calculate the
|
176
|
-
# required label width.
|
177
|
-
#
|
178
|
-
# require 'benchmark'
|
179
|
-
#
|
180
|
-
# array = (1..1000000).map { rand }
|
181
|
-
#
|
182
|
-
# Benchmark.bmbm do |x|
|
183
|
-
# x.report("sort!") { array.dup.sort! }
|
184
|
-
# x.report("sort") { array.dup.sort }
|
185
|
-
# end
|
186
|
-
#
|
187
|
-
# Generates:
|
188
|
-
#
|
189
|
-
# Rehearsal -----------------------------------------
|
190
|
-
# sort! 1.440000 0.010000 1.450000 ( 1.446833)
|
191
|
-
# sort 1.440000 0.000000 1.440000 ( 1.448257)
|
192
|
-
# -------------------------------- total: 2.890000sec
|
193
|
-
#
|
194
|
-
# user system total real
|
195
|
-
# sort! 1.460000 0.000000 1.460000 ( 1.458065)
|
196
|
-
# sort 1.450000 0.000000 1.450000 ( 1.455963)
|
197
|
-
#
|
198
|
-
# #bmbm yields a Benchmark::Job object and returns an array of Benchmark::Tms
|
199
|
-
# objects.
|
200
|
-
#
|
201
|
-
def self?.bmbm: (?Integer width) { (Job job) -> void } -> ::Array[Benchmark::Tms]
|
202
|
-
|
203
|
-
# Returns the time used to execute the given block as a Benchmark::Tms object.
|
204
|
-
# Takes `label` option.
|
205
|
-
#
|
206
|
-
# require 'benchmark'
|
207
|
-
#
|
208
|
-
# n = 1000000
|
209
|
-
#
|
210
|
-
# time = Benchmark.measure do
|
211
|
-
# n.times { a = "1" }
|
212
|
-
# end
|
213
|
-
# puts time
|
214
|
-
#
|
215
|
-
# Generates:
|
216
|
-
#
|
217
|
-
# 0.220000 0.000000 0.220000 ( 0.227313)
|
218
|
-
#
|
219
|
-
def self?.measure: (?String label) { () -> void } -> Benchmark::Tms
|
220
|
-
|
221
|
-
# Returns the elapsed real time used to execute the given block.
|
222
|
-
#
|
223
|
-
def self?.realtime: () { () -> void } -> Float
|
224
|
-
end
|
225
|
-
|
226
|
-
Benchmark::BENCHMARK_VERSION: String
|
227
|
-
|
228
|
-
# The default caption string (heading above the output times).
|
229
|
-
#
|
230
|
-
Benchmark::CAPTION: String
|
231
|
-
|
232
|
-
# The default format string used to display times. See also
|
233
|
-
# Benchmark::Tms#format.
|
234
|
-
#
|
235
|
-
Benchmark::FORMAT: String
|
236
|
-
|
237
|
-
class Benchmark::Job
|
238
|
-
# Prints the `label` and measured time for the block,
|
239
|
-
# formatted by `format`. See Tms#format for the
|
240
|
-
# formatting rules.
|
241
|
-
def item: (?String label) { () -> void } -> self
|
242
|
-
|
243
|
-
# An array of 2-element arrays, consisting of label and block pairs.
|
244
|
-
def list: () -> ::Array[untyped]
|
245
|
-
|
246
|
-
alias report item
|
247
|
-
|
248
|
-
# Length of the widest label in the #list.
|
249
|
-
def width: () -> Integer
|
250
|
-
end
|
251
|
-
|
252
|
-
class Benchmark::Report
|
253
|
-
# Prints the `label` and measured time for the block,
|
254
|
-
# formatted by `format`. See Tms#format for the
|
255
|
-
# formatting rules.
|
256
|
-
def item: (?String label, *untyped format) { () -> void } -> Tms
|
257
|
-
|
258
|
-
# An array of Benchmark::Tms objects representing each item.
|
259
|
-
def list: () -> ::Array[Benchmark::Tms]
|
260
|
-
|
261
|
-
alias report item
|
262
|
-
end
|
263
|
-
|
264
|
-
# A data object, representing the times associated with a benchmark measurement.
|
265
|
-
#
|
266
|
-
class Benchmark::Tms
|
267
|
-
# Returns a new Tms object obtained by memberwise multiplication of the
|
268
|
-
# individual times for this Tms object by `x`.
|
269
|
-
#
|
270
|
-
def *: (untyped x) -> untyped
|
271
|
-
|
272
|
-
# Returns a new Tms object obtained by memberwise summation of the individual
|
273
|
-
# times for this Tms object with those of the `other` Tms object. This method
|
274
|
-
# and #/() are useful for taking statistics.
|
275
|
-
#
|
276
|
-
def +: (untyped other) -> untyped
|
277
|
-
|
278
|
-
# Returns a new Tms object obtained by memberwise subtraction of the individual
|
279
|
-
# times for the `other` Tms object from those of this Tms object.
|
280
|
-
#
|
281
|
-
def -: (untyped other) -> untyped
|
282
|
-
|
283
|
-
# Returns a new Tms object obtained by memberwise division of the individual
|
284
|
-
# times for this Tms object by `x`. This method and #+() are useful for taking
|
285
|
-
# statistics.
|
286
|
-
#
|
287
|
-
def /: (untyped x) -> untyped
|
288
|
-
|
289
|
-
# Returns a new Tms object whose times are the sum of the times for this Tms
|
290
|
-
# object, plus the time required to execute the code block (`blk`).
|
291
|
-
#
|
292
|
-
def add: () { (*untyped) -> untyped } -> untyped
|
293
|
-
|
294
|
-
# An in-place version of #add. Changes the times of this Tms object by making it
|
295
|
-
# the sum of the times for this Tms object, plus the time required to execute
|
296
|
-
# the code block (`blk`).
|
297
|
-
#
|
298
|
-
def add!: () { (*untyped) -> untyped } -> untyped
|
299
|
-
|
300
|
-
# System CPU time of children
|
301
|
-
#
|
302
|
-
def cstime: () -> Float
|
303
|
-
|
304
|
-
# User CPU time of children
|
305
|
-
#
|
306
|
-
def cutime: () -> Float
|
307
|
-
|
308
|
-
# Returns the contents of this Tms object as a formatted string, according to a
|
309
|
-
# `format` string like that passed to Kernel.format. In addition, #format
|
310
|
-
# accepts the following extensions:
|
311
|
-
#
|
312
|
-
# `%u`
|
313
|
-
# : Replaced by the user CPU time, as reported by Tms#utime.
|
314
|
-
# `%y`
|
315
|
-
# : Replaced by the system CPU time, as reported by #stime (Mnemonic: y of
|
316
|
-
# "s*y*stem")
|
317
|
-
# `%U`
|
318
|
-
# : Replaced by the children's user CPU time, as reported by Tms#cutime
|
319
|
-
# `%Y`
|
320
|
-
# : Replaced by the children's system CPU time, as reported by Tms#cstime
|
321
|
-
# `%t`
|
322
|
-
# : Replaced by the total CPU time, as reported by Tms#total
|
323
|
-
# `%r`
|
324
|
-
# : Replaced by the elapsed real time, as reported by Tms#real
|
325
|
-
# `%n`
|
326
|
-
# : Replaced by the label string, as reported by Tms#label (Mnemonic: n of
|
327
|
-
# "*n*ame")
|
328
|
-
#
|
329
|
-
#
|
330
|
-
# If `format` is not given, FORMAT is used as default value, detailing the user,
|
331
|
-
# system and real elapsed time.
|
332
|
-
#
|
333
|
-
def format: (?String format, *untyped args) -> String
|
334
|
-
|
335
|
-
# Label
|
336
|
-
#
|
337
|
-
def label: () -> String
|
338
|
-
|
339
|
-
# Elapsed real time
|
340
|
-
#
|
341
|
-
def real: () -> Float
|
342
|
-
|
343
|
-
# System CPU time
|
344
|
-
#
|
345
|
-
def stime: () -> Float
|
346
|
-
|
347
|
-
# Returns a new 6-element array, consisting of the label, user CPU time, system
|
348
|
-
# CPU time, children's user CPU time, children's system CPU time and elapsed
|
349
|
-
# real time.
|
350
|
-
#
|
351
|
-
def to_a: () -> untyped
|
352
|
-
|
353
|
-
# Same as #format.
|
354
|
-
#
|
355
|
-
def to_s: () -> String
|
356
|
-
|
357
|
-
# Total time, that is `utime` + `stime` + `cutime` + `cstime`
|
358
|
-
#
|
359
|
-
def total: () -> Float
|
360
|
-
|
361
|
-
# User CPU time
|
362
|
-
#
|
363
|
-
def utime: () -> Float
|
364
|
-
end
|
365
|
-
|
366
|
-
# Default caption, see also Benchmark::CAPTION
|
367
|
-
#
|
368
|
-
Benchmark::Tms::CAPTION: String
|
369
|
-
|
370
|
-
# Default format string, see also Benchmark::FORMAT
|
371
|
-
#
|
372
|
-
Benchmark::Tms::FORMAT: String
|