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" | |
hash = {'key' => 1, :key => 2} | |
n = 5_000_000 | |
Benchmark.bm do |x| | |
x.report("strings") { n.times { hash['key'] } } | |
x.report("symbols") { n.times { hash[:key] } } | |
x.report("strings, set") { n.times { hash['key'] = 1 } } |
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
SQL_PARSER_REGEXP = /^(\w+)\s(\w+)\s\W*(\w+)/ | |
ActiveSupport::Notifications.subscribe "sql.active_record" do |name, start, finish, id, payload| | |
if payload[:name] == "SQL" | |
if Thread.current[:stats_context] # where I store the name of the request context | |
payload[:sql] =~ SQL_PARSER_REGEXP # $1 will be the query type, $3 the table | |
Statsd.timing("#{Thread.current[:stats_context]}.sql.#{$3}.#{$1}.query_time", | |
(finish - start) * 1000, 1) | |
end | |
end |
NewerOlder