1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
require "bundler/gem_tasks"
require "rake/testtask"
$LOAD_PATH.unshift File.expand_path("./lib", __dir__)
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
end
task :default => :test
task :bench do
require 'benchmark/ips'
require 'enumerable/statistics'
require 'mini_histogram'
array = 1000.times.map { rand }
histogram = MiniHistogram.new(array)
my_weights = histogram.weights
puts array.histogram.weights == my_weights
puts array.histogram.weights.inspect
puts my_weights.inspect
Benchmark.ips do |x|
x.report("enumerable stats") { array.histogram }
x.report("mini histogram ") {
MiniHistogram.new(array).weights
}
x.compare!
end
end
|