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
-- Filter an array of events such that there is only one event with each event_id. | |
-- When more than one event with the same event_id, is present, take the latest one. | |
CREATE OR REPLACE FUNCTION dedupe_events_2(events HSTORE[]) RETURNS HSTORE[] AS $$ | |
SELECT array_agg(event) | |
FROM ( | |
-- select first of elements with the same event_id by position in the array, descending. | |
SELECT first_value(event) as event | |
OVER (PARTITION BY (event -> 'event_id')::BIGINT ORDER BY index DESC) | |
FROM ( | |
-- Use unnest instead of generate_subscripts to turn an array into a set. |
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
#!/usr/bin/env ruby | |
require 'benchmark' | |
N = 10_000_000 | |
def no_capture | |
end | |
def block_capture(&_block) |
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
# acquire watch metrics | |
for c in wchs wchc wchp; do echo $c | nc zookeeper3.prod.pages 2181 >$c.zk3; done | |
# repeated inquiries of wchs show no jitter, these numbers are stable over times much longer | |
# than the for loop above | |
cat wchs.zk3 | |
2013 connections watching 218 paths | |
Total watches:5642 | |
# During this same period, the zk_watch_count metric being reported to graphite was ~ 9200 |
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
#!/usr/bin/env ruby | |
require 'benchmark' | |
require 'set' | |
N = 5_000_000 | |
MAX_CARD = 5 | |
ARRAYS = (0..MAX_CARD).map {|i| (1..i).to_a} |
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
#!/usr/bin/env ruby | |
require 'benchmark' | |
N = 1_000_000 | |
A = (0..10).to_a | |
def map_plain | |
A.map {|e| e.to_s} |
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
#!/usr/bin/env ruby | |
require 'set' | |
require 'benchmark' | |
N = 5 | |
HSZ = 150_000 | |
ASZ = 25_000 |
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
#!/usr/bin/env ruby | |
require 'benchmark' | |
# 456976 four character words | |
STR = ('aaaa'..'zzzz').to_a * ' ' | |
N = 10 | |
puts RUBY_DESCRIPTION | |
puts "#{N} times on string of size #{STR.size}" |
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
#!/usr/bin/env ruby | |
require 'benchmark' | |
require 'forwardable' | |
puts RUBY_DESCRIPTION | |
class TestMe | |
extend Forwardable | |
def_delegators :@arr, :each |
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
#!/usr/bin/env ruby | |
require 'benchmark' | |
require 'set' | |
N = 10_000_000 | |
Benchmark.bm do |x| | |
1.upto(10) do |i| | |
a = (0...i).to_a |
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
#!/usr/bin/env ruby | |
# Benchmark answers to http://stackoverflow.com/questions/13002594/handling-array-of-hashes | |
require 'benchmark' | |
A = [{"lib1"=>"30"}, {"lib2"=>"30"}, {"lib9"=>"31"}, {"lib2"=>"31"}, {"lib3"=>"31"}, {"lib1"=>"32"}, {"l\ | |
ib2"=>"32"}, {"lib1"=>"33"}, {"lib3"=>"36"}, {"lib2"=>"36"}, {"lib1"=>"37"}] | |
def to_a_flat | |
A.map(&:to_a).flatten(1).each_with_object({}) do |(k, v), h| |
NewerOlder