File: detection.rb

package info (click to toggle)
ruby-charlock-holmes 0.7.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,776 kB
  • ctags: 99
  • sloc: ruby: 435; ansic: 303; lisp: 237; cpp: 101; sh: 21; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 811 bytes parent folder | download | duplicates (2)
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
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)

RUBY_19 = !!(RUBY_VERSION =~ /1.9/)

require 'charlock_holmes'

# the chardet gem isn't compatible with 1.9
require 'UniversalDetector' unless RUBY_19

require 'benchmark'

CONTENT = File.read(File.expand_path('../test.txt', __FILE__))

TIMES = 100
DETECTOR = CharlockHolmes::EncodingDetector.new

Benchmark.bmbm do |x|
  # new detector every iteration
  x.report 'singleton call' do
    TIMES.times do
      CharlockHolmes::EncodingDetector.detect CONTENT
    end
  end

  # shared detector for all iterations
  x.report 'reusing a single detector' do
    TIMES.times do
      DETECTOR.detect CONTENT
    end
  end

  unless RUBY_19
    x.report 'chardet' do
      TIMES.times do
        UniversalDetector.chardet CONTENT
      end
    end
  end
end