https://github.com/mtchavez/rb-array-sorting
https://github.com/mtchavez/rb-array-sorting
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/mtchavez/rb-array-sorting
- Owner: mtchavez
- Created: 2012-12-08T19:40:54.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2012-12-08T23:18:51.000Z (over 12 years ago)
- Last Synced: 2025-02-04T15:32:41.697Z (4 months ago)
- Language: Ruby
- Size: 109 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## rb-array-sorting
Recursive merge sort in Ruby.
[](http://coderwall.com/mtchavez)### Merge Sort
Example:array = []
7000.times{ array << rand(500) }
array.merge_sort { |a,b| a <= b }### Quick Sort
Example:array = []
7000.times{ array << rand(500) }
array.quick_sort### Benchmarks
Benchmarks of merge and quick sort against ruby array sort:
require 'benchmark'
Benchmark.bm do |b|
b.report('ruby') { array.sort }
b.report('merge_sort') { array.merge_sort { |a,b| a <= b } }
b.report('quick_sort') { array.quick_sort }
enduser system total real
ruby 0.000000 0.000000 0.000000 ( 0.001410)
merge_sort 0.430000 0.020000 0.450000 ( 0.451126)
quick_sort 0.060000 0.000000 0.060000 ( 0.059994)### Specs
Run ```rake``` for specs.