9bc73cd81f
[Feature #13884] Reduce number of memory allocations for "and", "or" and "diff" operations on small arrays Very often, arrays are used to filter parameters and to select interesting items from 2 collections and very often these collections are small enough, for example: ```ruby SAFE_COLUMNS = [:id, :title, :created_at] def columns @all_columns & SAFE_COLUMNS end ``` In this patch, I got rid of unnecessary memory allocations for small arrays when "and", "or" and "diff" operations are performed. name | HEAD | PATCH -----------------+------:+------: array_small_and | 0.615 | 0.263 array_small_diff | 0.676 | 0.282 array_small_or | 0.953 | 0.463 name | PATCH -----------------+------: array_small_and | 2.343 array_small_diff | 2.392 array_small_or | 2.056 name | HEAD | PATCH -----------------+------:+------: array_small_and | 1.429 | 1.005 array_small_diff | 1.493 | 0.878 array_small_or | 1.672 | 1.152 name | PATCH -----------------+------: array_small_and | 1.422 array_small_diff | 1.700 array_small_or | 1.452 Author: Dmitry Bochkarev <dimabochkarev@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60057 b2dd03c8-39d4-4d8f-98ff-823fe69b080e |
||
---|---|---|
.. | ||
bundler | ||
mspec | ||
ruby | ||
README.md | ||
default.mspec |
README.md
spec/bundler
spec/bundler is rspec examples for bundler library(lib/bundler.rb, lib/bundler/*).
Running spec/bundler
To run rspec for bundler:
make test-bundler
spec/ruby
ruby/spec (https://github.com/ruby/spec/) is a test suite for the Ruby language.
Once a month, @eregon merges the in-tree copy under spec/ruby with the upstream repository, preserving the commits and history. The same happens for other implementations such as JRuby and TruffleRuby.
Feel welcome to modify the in-tree spec/ruby. This is the purpose of the in-tree copy, to facilitate contributions to ruby/spec for MRI developers.
New features, additional tests for existing features and
regressions tests are all welcome in ruby/spec.
There is very little behavior that is implementation-specific,
as in the end user programs tend to rely on every behavior MRI exhibits.
In other words: If adding a spec might reveal a bug in
another implementation, then it is worth adding it.
Currently, the only module which is MRI-specific is RubyVM
.
Runing ruby/spec
To run all specs:
make test-spec
Extra arguments can be added via MSPECOPT
.
For instance, to show the help:
make test-spec MSPECOPT=-h
You can also run the specs in parallel, which is currently experimental. It takes around 10s instead of 60s on a quad-core laptop.
make test-spec MSPECOPT=-j
To run a specific test, add its path to the command:
make test-spec MSPECOPT=spec/ruby/language/for_spec.rb
If ruby trunk is your current ruby
in $PATH
, you can also run mspec
directly:
# change ruby to trunk
ruby -v # => trunk
spec/mspec/bin/mspec spec/ruby/language/for_spec.rb
ruby/spec and test/
The main difference between a "spec" under spec/ruby and
a test under test/ is that specs are documenting what they test.
This is extremely valuable when reading these tests, as it
helps to quickly understand what specific behavior is tested,
and how a method should behave. Basic English is fine for spec descriptions.
Specs also tend to have few expectations (assertions) per spec,
as they specify one aspect of the behavior and not everything at once.
Beyond that, the syntax is slightly different but it does the same thing:
assert_equal 3, 1+2
is just (1+2).should == 3
.
Example:
describe "The for expression" do
it "iterates over an Enumerable passing each element to the block" do
j = 0
for i in 1..3
j += i
end
j.should == 6
end
end
For more details, see spec/ruby/CONTRIBUTING.md.