Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

An unordered group_by implementation that is a lot faster than the ordered version used in ActiveSupport version 2.2.x. This becomes apparent when used with large data sets.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 examples
Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Rakefile
Octocat-spinner-32 fast_group_by.gemspec
Octocat-spinner-32 readme.rdoc
readme.rdoc

Fast group_by

An unordered group_by implementation that is a lot faster than the ordered version used in ActiveSupport version 2.2.x. This becomes apparent when used with large data sets.

How to install

When you have setup gemcutter.org as a gem source, you can install it with:

sudo gem install fast_group_by

When you have setup gems.github.com as a gem source, you can install it with:

sudo gem install Narnach-fast_group_by

If you want tests, benchmarks and the project's history, you can clone the git repo and build the gem yourself:

git clone git://github.com/Narnach/fast_group_by.git
cd fast_group_by
rake install

Rationale

ActiveSupport uses OrderedHash in its Enumerable#group_by. In version 2.2.x, it uses nested Arrays to store data. Array#assoc is used to find if keys are already defined. For small Arrays, Array#assoc's linear search is about as fast as Hash#[]' tree search, but for larger data sets, the difference in lookup speed becomes noticeable. In version 2.3.x, there is a new implementation of OrderedHash that uses Hash instead of Array and is thus a lot faster. Using fast_group_by with ActiveSupport 2.3.x does not make much sense.

The reason why I wrote this is that the OrderedHash version took 66 seconds to group a collection of 50k items. The Hash version took less than 1 second.

License

Copyright © 2009 Wes Oldenbeuving

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Something went wrong with that request. Please try again.