-
-
Save beerlington/03ea4920421986700257 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
namespace :benchmark do | |
task :test => :environment do | |
# Repeat these values 100 times | |
values = [[ | |
{:timestamp => "2011-01-01 00:00", :value => 1}, | |
{:timestamp => "2011-01-01 00:15", :value => 2}, | |
{:timestamp => "2011-01-01 00:30", :value => 3} | |
],[ | |
{:timestamp => "2011-01-01 00:00", :value => 1}, | |
{:timestamp => "2011-01-01 00:30", :value => 3} | |
],[ | |
{:timestamp => "2011-01-01 00:00", :value => 1}, | |
{:timestamp => "2011-01-01 00:15", :value => 2}, | |
{:timestamp => "2011-01-01 00:30", :value => 3} | |
]].map{|x|[x]*100}.flatten(1) | |
Benchmark.bmbm do |x| | |
x.report("test 1") do | |
10_000.times do | |
all_stamps = values.flatten.map{|x| x[:timestamp]}.uniq.sort | |
values.each do |set| | |
my_stamps=set.map{|x|x[:timestamp]}.uniq | |
missing = all_stamps - my_stamps | |
set.concat( missing.map{ |stamp| {:timestamp => stamp, :value => nil} } ) | |
set.replace( set.sort_by{ |x| x[:timestamp] } ) | |
end | |
end | |
end | |
x.report("test2") do | |
10_000.times do | |
stamps = values.map{ |logs| logs.map{ |row| row[:timestamp] } }.flatten.uniq.sort | |
values.map!{ |logs| stamps.map { |ts| logs.select{ |row| row[:timestamp] == ts }.first || { :timestamp => ts, :value => nil } } } | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment