File: parse-bench.rb

package info (click to toggle)
libtmail-ruby 0.10.8-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 860 kB
  • ctags: 1,458
  • sloc: ruby: 8,406; ansic: 678; objc: 584; yacc: 305; makefile: 142
file content (68 lines) | stat: -rw-r--r-- 1,314 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#
# parser benchmark
#

require 'tmail'


if ARGV.empty? then
  $stderr.puts "usage: #{$0} <mhdir> <mhdir>..."
  exit 0
end
ARGV.each do |dname|
  unless File.directory? dname then
    $stderr.puts "not directory: #{dname}"
    exit 1
  end
end

$stdout.sync = true

$count   = 0
$failnum = 0
$dirfail = 0
$fieldname = ''
$dirname   = ''
$port  = nil

begin
  ARGV.each do |dirname|
    $dirname = dirname

    TMail::MhLoader.new( dirname ).each do |port|
      begin
        t = TMail::Mail.new( port )
        $port = port

        t.each_header do |key, field|
          $fieldname = key
          next if /received/i === key
          if ::TMail::StructH === field then
            field.instance_eval { parse unless @parsed }
          end
        end
      rescue TMail::SyntaxError
        $stderr.puts "fail in #{$count+1}, field #{$fieldname}"
        $stderr.puts $!.to_s
        $failnum += 1
        $dirfail += 1

        if $failnum % 10 == 0 then
          puts 'fail = ' + $failnum.to_s
          #raise
        end
      end

      $count += 1
      puts "end #{$count}" if $count % 50 == 0
    end

    puts "directory #{dirname} end, fail=#{$dirfail}"
    $dirfail = 0
  end
rescue
  puts "at #{$port.inspect}, non ParseError raised"
  raise
end

puts "parse #{$count} files, fail=#{$failnum}"