File: bm_valid.rb

package info (click to toggle)
ruby-public-suffix 3.0.3%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 284 kB
  • sloc: ruby: 1,431; makefile: 22
file content (101 lines) | stat: -rw-r--r-- 3,106 bytes parent folder | download | duplicates (3)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
require 'benchmark'
require_relative "../../lib/public_suffix"

NAME_SHORT  = "example.de"
NAME_MEDIUM = "www.subdomain.example.de"
NAME_LONG   = "one.two.three.four.five.example.de"
NAME_WILD   = "one.two.three.four.five.example.bd"
NAME_EXCP   = "one.two.three.four.five.www.ck"

IAAA = "www.example.ac"
IZZZ = "www.example.zone"

PAAA = "one.two.three.four.five.example.beep.pl"
PZZZ = "one.two.three.four.five.example.now.sh"

JP   = "www.yokoshibahikari.chiba.jp"
IT   = "www.example.it"
COM  = "www.example.com"

TIMES = (ARGV.first || 50_000).to_i

# Initialize
PublicSuffix.valid?("example.com")

Benchmark.bmbm(25) do |x|
  x.report("NAME_SHORT") do
    TIMES.times { PublicSuffix.valid?(NAME_SHORT) == true }
  end
  x.report("NAME_SHORT (noprivate)") do
    TIMES.times { PublicSuffix.valid?(NAME_SHORT, ignore_private: true) == true }
  end
  x.report("NAME_MEDIUM") do
    TIMES.times { PublicSuffix.valid?(NAME_MEDIUM) == true }
  end
  x.report("NAME_MEDIUM (noprivate)") do
    TIMES.times { PublicSuffix.valid?(NAME_MEDIUM, ignore_private: true) == true }
  end
  x.report("NAME_LONG") do
    TIMES.times { PublicSuffix.valid?(NAME_LONG) == true }
  end
  x.report("NAME_LONG (noprivate)") do
    TIMES.times { PublicSuffix.valid?(NAME_LONG, ignore_private: true) == true }
  end
  x.report("NAME_WILD") do
    TIMES.times { PublicSuffix.valid?(NAME_WILD) == true }
  end
  x.report("NAME_WILD (noprivate)") do
    TIMES.times { PublicSuffix.valid?(NAME_WILD, ignore_private: true) == true }
  end
  x.report("NAME_EXCP") do
    TIMES.times { PublicSuffix.valid?(NAME_EXCP) == true }
  end
  x.report("NAME_EXCP (noprivate)") do
    TIMES.times { PublicSuffix.valid?(NAME_EXCP, ignore_private: true) == true }
  end

  x.report("IAAA") do
    TIMES.times { PublicSuffix.valid?(IAAA) == true }
  end
  x.report("IAAA (noprivate)") do
    TIMES.times { PublicSuffix.valid?(IAAA, ignore_private: true) == true }
  end
  x.report("IZZZ") do
    TIMES.times { PublicSuffix.valid?(IZZZ) == true }
  end
  x.report("IZZZ (noprivate)") do
    TIMES.times { PublicSuffix.valid?(IZZZ, ignore_private: true) == true }
  end

  x.report("PAAA") do
    TIMES.times { PublicSuffix.valid?(PAAA) == true }
  end
  x.report("PAAA (noprivate)") do
    TIMES.times { PublicSuffix.valid?(PAAA, ignore_private: true) == true }
  end
  x.report("PZZZ") do
    TIMES.times { PublicSuffix.valid?(PZZZ) == true }
  end
  x.report("PZZZ (noprivate)") do
    TIMES.times { PublicSuffix.valid?(PZZZ, ignore_private: true) == true }
  end

  x.report("JP") do
    TIMES.times { PublicSuffix.valid?(JP) == true }
  end
  x.report("JP (noprivate)") do
    TIMES.times { PublicSuffix.valid?(JP, ignore_private: true) == true }
  end
  x.report("IT") do
    TIMES.times { PublicSuffix.valid?(IT) == true }
  end
  x.report("IT (noprivate)") do
    TIMES.times { PublicSuffix.valid?(IT, ignore_private: true) == true }
  end
  x.report("COM") do
    TIMES.times { PublicSuffix.valid?(COM) == true }
  end
  x.report("COM (noprivate)") do
    TIMES.times { PublicSuffix.valid?(COM, ignore_private: true) == true }
  end
end