Skip to content

Instantly share code, notes, and snippets.

@glurp
Created December 11, 2012 12:31
Show Gist options
  • Select an option

  • Save glurp/4258232 to your computer and use it in GitHub Desktop.

Select an option

Save glurp/4258232 to your computer and use it in GitHub Desktop.
rupy source example
require 'benchmark'
REP = 10
puts 'Generating data...'
class Array
def qsort
return self if length <= 1
pivot = self[0]
less, greatereq = self[1..-1].partition { |x| x < pivot }
less.qsort +[pivot] + greatereq.qsort
data = [10, 17].map do |i|
(1 << i).times.map { rand 1000000 }
puts 'done'
def n_min(l,n) (1..n).map {a=l.min ; l=l-[a]; a } end
Benchmark.bm 30 do |x|
[4, 20, 100].each do |n|
data.each do |array|
x.report "\n#{n}/#{array.size} items sort"
REP.times do
array.qsort[0, n]
x.report "#{n}/#{array.size} items n_min"
REP.times
n_min array, n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment