Postfixログパースベンチマーク
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 'postfix_status_line' | |
it = 5 | |
n = 500000 | |
status_lines = "Feb 27 09:02:37 MyHOSTNAME postfix/smtp[26490]: D53A72713E5: to=<myemail@bellsouth.net>, relay=gateway-f1.isp.att.net[204.127.217.16]:25, delay=0.57, delays=0.11/0.03/0.23/0.19, dsn=2.0.0, status=sent (250 ok ; id=20120227140036M0700qer4ne)" | |
r = /^(?<time>[^ ]* [^ ]* [^ ]*) (?<host>[^ ]+) (?<ident>[a-zA-Z0-9_\/\.\-]*)(?:\[(?<pid>[0-9]+)\])?[^\:]*\: (?<key>[^:]+): ?((to|from)=(<(?<address>[^>]+)>)?)?,( ?(orig_to=<(?<orig_to>[^>]+)>),)? ?(relay=(?<relay>[^ ]+)), ?(delay=(?<delay>[^ ]+)), ?(delays=(?<delays>[^ ]+)), ?(dsn=(?<dsn>[^ ]+)), ?(status=(?<status>[^,]+))/ | |
r_m = /^(?<time>[^ ]* [^ ]* [^ ]*) (?<host>[^ ]+) (?<ident>[a-zA-Z0-9_\/\.\-]*)(?:\[(?<pid>[0-9]+)\])?[^\:]*\: (?<key>[^:]+): ?((to|from)=(<(?:[^@]+@)?(?<address>[^>]+)>)?)?,( ?(orig_to=<(?<orig_to>[^>]+)>),)? ?(relay=(?<relay>[^ ]+)), ?(delay=(?<delay>[^ ]+)), ?(delays=(?<delays>[^ ]+)), ?(dsn=(?<dsn>[^ ]+)), ?(status=(?<status>[^ ,]+)(?: (?<status_detail>[^,]+))?)/ | |
Benchmark.bm(20, ">sec/prs:", ">prs/sec:") do |x| | |
rs = [] | |
it.times do |i| | |
i += 1 | |
rs << x.report("#{Time.now.strftime('%X')} psl(#{i}):") do | |
for i in 1..n | |
PostfixStatusLine.parse(status_lines, false) | |
end | |
end | |
end | |
pps = rs.inject(&:+) / it / n | |
tp = Benchmark::Tms.new(1/pps.utime, 1/pps.stime, 1/pps.cutime, 1/pps.cstime, 1/pps.real) | |
[pps, tp] | |
end | |
sleep 3 | |
Benchmark.bm(20, ">sec/prs:", ">prs/sec:") do |x| | |
rs = [] | |
it.times do |i| | |
i += 1 | |
rs << x.report("#{Time.now.strftime('%X')} psl+m(#{i}):") do | |
for i in 1..n | |
PostfixStatusLine.parse(status_lines) | |
end | |
end | |
end | |
pps = rs.inject(&:+) / it / n | |
tp = Benchmark::Tms.new(1/pps.utime, 1/pps.stime, 1/pps.cutime, 1/pps.cstime, 1/pps.real) | |
[pps, tp] | |
end | |
sleep 3 | |
Benchmark.bm(20, ">sec/prs:", ">prs/sec:") do |x| | |
rs = [] | |
it.times do |i| | |
i += 1 | |
rs << x.report("#{Time.now.strftime('%X')} rgx(#{i}):") do | |
for i in 1..n | |
m = r.match(status_lines) | |
h = {} | |
m.names.each {|n| h[n] = m[n] } | |
#=> {"time"=>"Feb 27 09:02:37", "host"=>"MyHOSTNAME", "ident"=>"postfix/smtp", "pid"=>"26490", "key"=>"D53A72713E5", "address"=>"myemail@bellsouth.net", "orig_to"=>nil, "relay"=>"gateway-f1.isp.att.net[204.127.217.16]:25", "delay"=>"0.57", "delays"=>"0.11/0.03/0.23/0.19", "dsn"=>"2.0.0", "status"=>"sent (250 ok ; id=20120227140036M0700qer4ne)"} | |
end | |
end | |
end | |
pps = rs.inject(&:+) / it / n | |
tp = Benchmark::Tms.new(1/pps.utime, 1/pps.stime, 1/pps.cutime, 1/pps.cstime, 1/pps.real) | |
[pps, tp] | |
end | |
sleep 3 | |
Benchmark.bm(20, ">sec/prs:", ">prs/sec:") do |x| | |
rs = [] | |
it.times do |i| | |
i += 1 | |
rs << x.report("#{Time.now.strftime('%X')} rgx+m(#{i}):") do | |
for i in 1..n | |
m = r_m.match(status_lines) | |
h = {} | |
m.names.each {|n| h[n] = m[n] } | |
#=> {"time"=>"Feb 27 09:02:37", "host"=>"MyHOSTNAME", "ident"=>"postfix/smtp", "pid"=>"26490", "key"=>"D53A72713E5", "address"=>"bellsouth.net", "orig_to"=>nil, "relay"=>"gateway-f1.isp.att.net[204.127.217.16]:25", "delay"=>"0.57", "delays"=>"0.11/0.03/0.23/0.19", "dsn"=>"2.0.0", "status"=>"sent", "status_detail"=>"(250 ok ; id=20120227140036M0700qer4ne)"} | |
end | |
end | |
end | |
pps = rs.inject(&:+) / it / n | |
tp = Benchmark::Tms.new(1/pps.utime, 1/pps.stime, 1/pps.cutime, 1/pps.cstime, 1/pps.real) | |
[pps, tp] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment