File: Rakefile

package info (click to toggle)
ruby-simple-po-parser 1.1.5-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 224 kB
  • sloc: ruby: 646; makefile: 4
file content (64 lines) | stat: -rw-r--r-- 2,143 bytes parent folder | download
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
# encoding: utf-8

require 'rubygems'
require 'rake'
require 'rspec/core/rake_task'
require 'bundler/gem_tasks'

task :default => :spec

desc "Generate a random po file to \"test/benchmark.po\". Takes optional rake args for number of entries"
task 'generate_random_pofile', :messages, :obsoletes do |t, args|
  args.with_defaults(:messages => "200", :obsoletes => "10")
  require_relative 'spec/utils/random_pofile_generator'
  PoParser::RandomPoFileGenerator.generate_file(
    File.expand_path("test/benchmark.po", __dir__), args[:messages].to_i, args[:obsoletes].to_i
  )
end

namespace :parser do
  require 'benchmark'
  require 'simple_po_parser'

  desc "Benchmark of 100 full PoParser runs of test/benchmark.po"
  task "benchmark" do
    pofile = File.expand_path("test/benchmark.po", __dir__)
    Benchmark.bmbm do |x|
      x.report("Parser:") {100.times { SimplePoParser.parse(pofile) }}
    end
  end

  desc "Generate 5 random PO files with 100 to 500 messages and benchmark each full PoParser run"
  task 'five_random_po_full' do
    include Benchmark
    require_relative 'spec/utils/random_pofile_generator'
    pofile = File.expand_path("test/benchmark.po.tmp", __dir__)
    Benchmark.benchmark(CAPTION, 6, FORMAT, "total:") do |x|
      total = nil
      total_length = 0
      for i in 0..5 do
        length = (Random.new.rand * 400.0 + 100).to_i
        total_length += length
        puts "Benchmarking file of length #{length}"
        SimplePoParser::RandomPoFileGenerator.generate_file(pofile, length)
        t = x.report("try#{i}:") {SimplePoParser.parse(pofile)}
        File.unlink(pofile)
        total = total ? total+t : t
      end
      puts "Total message length #{total_length}"
      [total]
    end
  end

  desc "Show ruby-prof profiler for spec/fixtures/complex_entry.po"
  task "profile_parser" do
    require 'ruby-prof'
    po_message = File.read(File.expand_path("spec/simple_po_parser/fixtures/complex_entry.po", __dir__))
    RubyProf.start
    SimplePoParser.parse_message(po_message)
    result = RubyProf.stop

    printer = RubyProf::FlatPrinter.new(result)
    printer.print(STDOUT)
  end
end