Advertisement
Guest User

Untitled

a guest
Dec 23rd, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. require 'benchmark'
  3. require 'postfix_status_line'
  4.  
  5. it = 5
  6. n = 500000
  7.  
  8. 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)"
  9.  
  10. 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>[^,]+))/
  11.  
  12. 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>[^,]+))?)/
  13.  
  14. Benchmark.bm(20, ">sec/prs:", ">prs/sec:") do |x|
  15. rs = []
  16.  
  17. it.times do |i|
  18. i += 1
  19.  
  20. rs << x.report("#{Time.now.strftime('%X')} psl(#{i}):") do
  21. for i in 1..n
  22. PostfixStatusLine.parse(status_lines, false)
  23. end
  24. end
  25. end
  26.  
  27. pps = rs.inject(&:+) / it / n
  28. tp = Benchmark::Tms.new(1/pps.utime, 1/pps.stime, 1/pps.cutime, 1/pps.cstime, 1/pps.real)
  29. [pps, tp]
  30. end
  31.  
  32. sleep 3
  33.  
  34. Benchmark.bm(20, ">sec/prs:", ">prs/sec:") do |x|
  35. rs = []
  36.  
  37. it.times do |i|
  38. i += 1
  39.  
  40. rs << x.report("#{Time.now.strftime('%X')} psl+m(#{i}):") do
  41. for i in 1..n
  42. PostfixStatusLine.parse(status_lines)
  43. end
  44. end
  45. end
  46.  
  47. pps = rs.inject(&:+) / it / n
  48. tp = Benchmark::Tms.new(1/pps.utime, 1/pps.stime, 1/pps.cutime, 1/pps.cstime, 1/pps.real)
  49. [pps, tp]
  50. end
  51.  
  52. sleep 3
  53.  
  54. Benchmark.bm(20, ">sec/prs:", ">prs/sec:") do |x|
  55. rs = []
  56.  
  57. it.times do |i|
  58. i += 1
  59.  
  60. rs << x.report("#{Time.now.strftime('%X')} rgx(#{i}):") do
  61. for i in 1..n
  62. m = r.match(status_lines)
  63. h = {}
  64. m.names.each {|n| h[n] = m[n] }
  65. #=> {"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)"}
  66. end
  67. end
  68. end
  69.  
  70. pps = rs.inject(&:+) / it / n
  71. tp = Benchmark::Tms.new(1/pps.utime, 1/pps.stime, 1/pps.cutime, 1/pps.cstime, 1/pps.real)
  72. [pps, tp]
  73. end
  74.  
  75. sleep 3
  76.  
  77. Benchmark.bm(20, ">sec/prs:", ">prs/sec:") do |x|
  78. rs = []
  79.  
  80. it.times do |i|
  81. i += 1
  82.  
  83. rs << x.report("#{Time.now.strftime('%X')} rgx+m(#{i}):") do
  84. for i in 1..n
  85. m = r_m.match(status_lines)
  86. h = {}
  87. m.names.each {|n| h[n] = m[n] }
  88. #=> {"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)"}
  89. end
  90. end
  91. end
  92.  
  93. pps = rs.inject(&:+) / it / n
  94. tp = Benchmark::Tms.new(1/pps.utime, 1/pps.stime, 1/pps.cutime, 1/pps.cstime, 1/pps.real)
  95. [pps, tp]
  96. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement