public_suffix 5.0.3 → 5.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,66 +0,0 @@
1
- require 'benchmark'
2
- require_relative "../../lib/public_suffix"
3
-
4
- NAME_SHORT = "example.de"
5
- NAME_MEDIUM = "www.subdomain.example.de"
6
- NAME_LONG = "one.two.three.four.five.example.de"
7
- NAME_WILD = "one.two.three.four.five.example.bd"
8
- NAME_EXCP = "one.two.three.four.five.www.ck"
9
-
10
- IAAA = "www.example.ac"
11
- IZZZ = "www.example.zone"
12
-
13
- PAAA = "one.two.three.four.five.example.beep.pl"
14
- PZZZ = "one.two.three.four.five.example.now.sh"
15
-
16
- JP = "www.yokoshibahikari.chiba.jp"
17
- IT = "www.example.it"
18
- COM = "www.example.com"
19
-
20
- TIMES = (ARGV.first || 50_000).to_i
21
-
22
- # Initialize
23
- PublicSuffixList = PublicSuffix::List.default
24
- PublicSuffixList.find("example.com")
25
-
26
- Benchmark.bmbm(25) do |x|
27
- x.report("NAME_SHORT") do
28
- TIMES.times { PublicSuffixList.find(NAME_SHORT) != nil }
29
- end
30
- x.report("NAME_MEDIUM") do
31
- TIMES.times { PublicSuffixList.find(NAME_MEDIUM) != nil }
32
- end
33
- x.report("NAME_LONG") do
34
- TIMES.times { PublicSuffixList.find(NAME_LONG) != nil }
35
- end
36
- x.report("NAME_WILD") do
37
- TIMES.times { PublicSuffixList.find(NAME_WILD) != nil }
38
- end
39
- x.report("NAME_EXCP") do
40
- TIMES.times { PublicSuffixList.find(NAME_EXCP) != nil }
41
- end
42
-
43
- x.report("IAAA") do
44
- TIMES.times { PublicSuffixList.find(IAAA) != nil }
45
- end
46
- x.report("IZZZ") do
47
- TIMES.times { PublicSuffixList.find(IZZZ) != nil }
48
- end
49
-
50
- x.report("PAAA") do
51
- TIMES.times { PublicSuffixList.find(PAAA) != nil }
52
- end
53
- x.report("PZZZ") do
54
- TIMES.times { PublicSuffixList.find(PZZZ) != nil }
55
- end
56
-
57
- x.report("JP") do
58
- TIMES.times { PublicSuffixList.find(JP) != nil }
59
- end
60
- x.report("IT") do
61
- TIMES.times { PublicSuffixList.find(IT) != nil }
62
- end
63
- x.report("COM") do
64
- TIMES.times { PublicSuffixList.find(COM) != nil }
65
- end
66
- end
@@ -1,102 +0,0 @@
1
- require 'benchmark'
2
- require_relative "../../lib/public_suffix"
3
-
4
- NAME_SHORT = "example.de"
5
- NAME_MEDIUM = "www.subdomain.example.de"
6
- NAME_LONG = "one.two.three.four.five.example.de"
7
- NAME_WILD = "one.two.three.four.five.example.bd"
8
- NAME_EXCP = "one.two.three.four.five.www.ck"
9
-
10
- IAAA = "www.example.ac"
11
- IZZZ = "www.example.zone"
12
-
13
- PAAA = "one.two.three.four.five.example.beep.pl"
14
- PZZZ = "one.two.three.four.five.example.now.sh"
15
-
16
- JP = "www.yokoshibahikari.chiba.jp"
17
- IT = "www.example.it"
18
- COM = "www.example.com"
19
-
20
- TIMES = (ARGV.first || 50_000).to_i
21
-
22
- # Initialize
23
- PublicSuffixList = PublicSuffix::List.default
24
- PublicSuffixList.find("example.com")
25
-
26
- Benchmark.bmbm(25) do |x|
27
- x.report("NAME_SHORT") do
28
- TIMES.times { PublicSuffixList.find(NAME_SHORT) != nil }
29
- end
30
- x.report("NAME_SHORT (noprivate)") do
31
- TIMES.times { PublicSuffixList.find(NAME_SHORT, ignore_private: true) != nil }
32
- end
33
- x.report("NAME_MEDIUM") do
34
- TIMES.times { PublicSuffixList.find(NAME_MEDIUM) != nil }
35
- end
36
- x.report("NAME_MEDIUM (noprivate)") do
37
- TIMES.times { PublicSuffixList.find(NAME_MEDIUM, ignore_private: true) != nil }
38
- end
39
- x.report("NAME_LONG") do
40
- TIMES.times { PublicSuffixList.find(NAME_LONG) != nil }
41
- end
42
- x.report("NAME_LONG (noprivate)") do
43
- TIMES.times { PublicSuffixList.find(NAME_LONG, ignore_private: true) != nil }
44
- end
45
- x.report("NAME_WILD") do
46
- TIMES.times { PublicSuffixList.find(NAME_WILD) != nil }
47
- end
48
- x.report("NAME_WILD (noprivate)") do
49
- TIMES.times { PublicSuffixList.find(NAME_WILD, ignore_private: true) != nil }
50
- end
51
- x.report("NAME_EXCP") do
52
- TIMES.times { PublicSuffixList.find(NAME_EXCP) != nil }
53
- end
54
- x.report("NAME_EXCP (noprivate)") do
55
- TIMES.times { PublicSuffixList.find(NAME_EXCP, ignore_private: true) != nil }
56
- end
57
-
58
- x.report("IAAA") do
59
- TIMES.times { PublicSuffixList.find(IAAA) != nil }
60
- end
61
- x.report("IAAA (noprivate)") do
62
- TIMES.times { PublicSuffixList.find(IAAA, ignore_private: true) != nil }
63
- end
64
- x.report("IZZZ") do
65
- TIMES.times { PublicSuffixList.find(IZZZ) != nil }
66
- end
67
- x.report("IZZZ (noprivate)") do
68
- TIMES.times { PublicSuffixList.find(IZZZ, ignore_private: true) != nil }
69
- end
70
-
71
- x.report("PAAA") do
72
- TIMES.times { PublicSuffixList.find(PAAA) != nil }
73
- end
74
- x.report("PAAA (noprivate)") do
75
- TIMES.times { PublicSuffixList.find(PAAA, ignore_private: true) != nil }
76
- end
77
- x.report("PZZZ") do
78
- TIMES.times { PublicSuffixList.find(PZZZ) != nil }
79
- end
80
- x.report("PZZZ (noprivate)") do
81
- TIMES.times { PublicSuffixList.find(PZZZ, ignore_private: true) != nil }
82
- end
83
-
84
- x.report("JP") do
85
- TIMES.times { PublicSuffixList.find(JP) != nil }
86
- end
87
- x.report("JP (noprivate)") do
88
- TIMES.times { PublicSuffixList.find(JP, ignore_private: true) != nil }
89
- end
90
- x.report("IT") do
91
- TIMES.times { PublicSuffixList.find(IT) != nil }
92
- end
93
- x.report("IT (noprivate)") do
94
- TIMES.times { PublicSuffixList.find(IT, ignore_private: true) != nil }
95
- end
96
- x.report("COM") do
97
- TIMES.times { PublicSuffixList.find(COM) != nil }
98
- end
99
- x.report("COM (noprivate)") do
100
- TIMES.times { PublicSuffixList.find(COM, ignore_private: true) != nil }
101
- end
102
- end
@@ -1,91 +0,0 @@
1
- require 'benchmark/ips'
2
-
3
- STRING = "www.subdomain.example.com"
4
- ARRAY = %w(
5
- com
6
- example.com
7
- subdomain.example.com
8
- www.subdomain.example.com
9
- )
10
-
11
- def tokenizer1(string)
12
- parts = string.split(".").reverse!
13
- index = 0
14
- query = parts[index]
15
- names = []
16
-
17
- loop do
18
- names << query
19
-
20
- index += 1
21
- break if index >= parts.size
22
- query = parts[index] + "." + query
23
- end
24
- names
25
- end
26
-
27
- def tokenizer2(string)
28
- parts = string.split(".")
29
- index = parts.size - 1
30
- query = parts[index]
31
- names = []
32
-
33
- loop do
34
- names << query
35
-
36
- index -= 1
37
- break if index < 0
38
- query = parts[index] + "." + query
39
- end
40
- names
41
- end
42
-
43
- def tokenizer3(string)
44
- isx = string.size
45
- idx = string.size - 1
46
- names = []
47
-
48
- loop do
49
- isx = string.rindex(".", isx - 1) || -1
50
- names << string[isx + 1, idx - isx]
51
-
52
- break if isx <= 0
53
- end
54
- names
55
- end
56
-
57
- def tokenizer4(string)
58
- isx = string.size
59
- idx = string.size - 1
60
- names = []
61
-
62
- loop do
63
- isx = string.rindex(".", isx - 1) || -1
64
- names << string[(isx+1)..idx]
65
-
66
- break if isx <= 0
67
- end
68
- names
69
- end
70
-
71
- (x = tokenizer1(STRING)) == ARRAY or fail("tokenizer1 failed: #{x.inspect}")
72
- (x = tokenizer2(STRING)) == ARRAY or fail("tokenizer2 failed: #{x.inspect}")
73
- (x = tokenizer3(STRING)) == ARRAY or fail("tokenizer3 failed: #{x.inspect}")
74
- (x = tokenizer4(STRING)) == ARRAY or fail("tokenizer4 failed: #{x.inspect}")
75
-
76
- Benchmark.ips do |x|
77
- x.report("tokenizer1") do
78
- tokenizer1(STRING).is_a?(Array)
79
- end
80
- x.report("tokenizer2") do
81
- tokenizer2(STRING).is_a?(Array)
82
- end
83
- x.report("tokenizer3") do
84
- tokenizer3(STRING).is_a?(Array)
85
- end
86
- x.report("tokenizer4") do
87
- tokenizer4(STRING).is_a?(Array)
88
- end
89
-
90
- x.compare!
91
- end
@@ -1,26 +0,0 @@
1
- require 'benchmark'
2
- require_relative "../../lib/public_suffix"
3
-
4
- JP = "www.yokoshibahikari.chiba.jp"
5
-
6
- TIMES = (ARGV.first || 50_000).to_i
7
-
8
- # Initialize
9
- class PublicSuffix::List
10
- public :select
11
- end
12
- PublicSuffixList = PublicSuffix::List.default
13
- PublicSuffixList.select("example.jp")
14
- PublicSuffixList.find("example.jp")
15
-
16
- Benchmark.bmbm(25) do |x|
17
- x.report("JP select") do
18
- TIMES.times { PublicSuffixList.select(JP) }
19
- end
20
- x.report("JP find") do
21
- TIMES.times { PublicSuffixList.find(JP) }
22
- end
23
- # x.report("JP (noprivate)") do
24
- # TIMES.times { PublicSuffixList.find(JP, ignore_private: true) != nil }
25
- # end
26
- end
@@ -1,25 +0,0 @@
1
- require 'benchmark'
2
- require_relative "../../lib/public_suffix"
3
-
4
- JP = "www.yokoshibahikari.chiba.jp"
5
-
6
- TIMES = (ARGV.first || 50_000).to_i
7
-
8
- # Initialize
9
- class PublicSuffix::List
10
- public :select
11
- end
12
- PublicSuffixList = PublicSuffix::List.default
13
- PublicSuffixList.select("example.jp")
14
-
15
- Benchmark.bmbm(25) do |x|
16
- x.report("select jp") do
17
- TIMES.times { PublicSuffixList.select("jp") }
18
- end
19
- x.report("select example.jp") do
20
- TIMES.times { PublicSuffixList.select("example.jp") }
21
- end
22
- x.report("select www.example.jp") do
23
- TIMES.times { PublicSuffixList.select("www.example.jp") }
24
- end
25
- end
@@ -1,101 +0,0 @@
1
- require 'benchmark'
2
- require_relative "../../lib/public_suffix"
3
-
4
- NAME_SHORT = "example.de"
5
- NAME_MEDIUM = "www.subdomain.example.de"
6
- NAME_LONG = "one.two.three.four.five.example.de"
7
- NAME_WILD = "one.two.three.four.five.example.bd"
8
- NAME_EXCP = "one.two.three.four.five.www.ck"
9
-
10
- IAAA = "www.example.ac"
11
- IZZZ = "www.example.zone"
12
-
13
- PAAA = "one.two.three.four.five.example.beep.pl"
14
- PZZZ = "one.two.three.four.five.example.now.sh"
15
-
16
- JP = "www.yokoshibahikari.chiba.jp"
17
- IT = "www.example.it"
18
- COM = "www.example.com"
19
-
20
- TIMES = (ARGV.first || 50_000).to_i
21
-
22
- # Initialize
23
- PublicSuffix.valid?("example.com")
24
-
25
- Benchmark.bmbm(25) do |x|
26
- x.report("NAME_SHORT") do
27
- TIMES.times { PublicSuffix.valid?(NAME_SHORT) == true }
28
- end
29
- x.report("NAME_SHORT (noprivate)") do
30
- TIMES.times { PublicSuffix.valid?(NAME_SHORT, ignore_private: true) == true }
31
- end
32
- x.report("NAME_MEDIUM") do
33
- TIMES.times { PublicSuffix.valid?(NAME_MEDIUM) == true }
34
- end
35
- x.report("NAME_MEDIUM (noprivate)") do
36
- TIMES.times { PublicSuffix.valid?(NAME_MEDIUM, ignore_private: true) == true }
37
- end
38
- x.report("NAME_LONG") do
39
- TIMES.times { PublicSuffix.valid?(NAME_LONG) == true }
40
- end
41
- x.report("NAME_LONG (noprivate)") do
42
- TIMES.times { PublicSuffix.valid?(NAME_LONG, ignore_private: true) == true }
43
- end
44
- x.report("NAME_WILD") do
45
- TIMES.times { PublicSuffix.valid?(NAME_WILD) == true }
46
- end
47
- x.report("NAME_WILD (noprivate)") do
48
- TIMES.times { PublicSuffix.valid?(NAME_WILD, ignore_private: true) == true }
49
- end
50
- x.report("NAME_EXCP") do
51
- TIMES.times { PublicSuffix.valid?(NAME_EXCP) == true }
52
- end
53
- x.report("NAME_EXCP (noprivate)") do
54
- TIMES.times { PublicSuffix.valid?(NAME_EXCP, ignore_private: true) == true }
55
- end
56
-
57
- x.report("IAAA") do
58
- TIMES.times { PublicSuffix.valid?(IAAA) == true }
59
- end
60
- x.report("IAAA (noprivate)") do
61
- TIMES.times { PublicSuffix.valid?(IAAA, ignore_private: true) == true }
62
- end
63
- x.report("IZZZ") do
64
- TIMES.times { PublicSuffix.valid?(IZZZ) == true }
65
- end
66
- x.report("IZZZ (noprivate)") do
67
- TIMES.times { PublicSuffix.valid?(IZZZ, ignore_private: true) == true }
68
- end
69
-
70
- x.report("PAAA") do
71
- TIMES.times { PublicSuffix.valid?(PAAA) == true }
72
- end
73
- x.report("PAAA (noprivate)") do
74
- TIMES.times { PublicSuffix.valid?(PAAA, ignore_private: true) == true }
75
- end
76
- x.report("PZZZ") do
77
- TIMES.times { PublicSuffix.valid?(PZZZ) == true }
78
- end
79
- x.report("PZZZ (noprivate)") do
80
- TIMES.times { PublicSuffix.valid?(PZZZ, ignore_private: true) == true }
81
- end
82
-
83
- x.report("JP") do
84
- TIMES.times { PublicSuffix.valid?(JP) == true }
85
- end
86
- x.report("JP (noprivate)") do
87
- TIMES.times { PublicSuffix.valid?(JP, ignore_private: true) == true }
88
- end
89
- x.report("IT") do
90
- TIMES.times { PublicSuffix.valid?(IT) == true }
91
- end
92
- x.report("IT (noprivate)") do
93
- TIMES.times { PublicSuffix.valid?(IT, ignore_private: true) == true }
94
- end
95
- x.report("COM") do
96
- TIMES.times { PublicSuffix.valid?(COM) == true }
97
- end
98
- x.report("COM (noprivate)") do
99
- TIMES.times { PublicSuffix.valid?(COM, ignore_private: true) == true }
100
- end
101
- end
@@ -1,12 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path("../../lib", __dir__)
2
-
3
- require "memory_profiler"
4
- require "public_suffix"
5
-
6
- PublicSuffix::List.default
7
-
8
- report = MemoryProfiler.report do
9
- PublicSuffix.domain("www.example.com")
10
- end
11
-
12
- report.pretty_print
@@ -1,12 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path("../../lib", __dir__)
2
-
3
- require "memory_profiler"
4
- require "public_suffix"
5
-
6
- PublicSuffix::List.default
7
-
8
- report = MemoryProfiler.report do
9
- PublicSuffix::List.default.find("www.example.com")
10
- end
11
-
12
- report.pretty_print
@@ -1,12 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path("../../lib", __dir__)
2
-
3
- require "memory_profiler"
4
- require "public_suffix"
5
-
6
- PublicSuffix::List.default
7
-
8
- report = MemoryProfiler.report do
9
- PublicSuffix::List.default.find("a.b.ide.kyoto.jp")
10
- end
11
-
12
- report.pretty_print
@@ -1,11 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path("../../lib", __dir__)
2
-
3
- require "memory_profiler"
4
- require "public_suffix"
5
-
6
- report = MemoryProfiler.report do
7
- PublicSuffix::List.default
8
- end
9
-
10
- report.pretty_print
11
- # report.pretty_print(to_file: 'profiler-%s-%d.txt' % [ARGV[0], Time.now.to_i])
@@ -1,11 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path("../../lib", __dir__)
2
-
3
- require_relative "object_binsize"
4
- require "public_suffix"
5
-
6
- list = PublicSuffix::List.default
7
- puts "#{list.size} rules:"
8
-
9
- prof = ObjectBinsize.new
10
- prof.report(PublicSuffix::List.default, label: "PublicSuffix::List size")
11
- prof.report(PublicSuffix::List.default.instance_variable_get(:@rules), label: "Size of rules")
@@ -1,57 +0,0 @@
1
- require 'tempfile'
2
-
3
- # A very simple memory profiles that checks the full size of a variable
4
- # by serializing into a binary file.
5
- #
6
- # Yes, I know this is very rough, but there are cases where ObjectSpace.memsize_of
7
- # doesn't cooperate, and this is one of the possible workarounds.
8
- #
9
- # For certain cases, it works (TM).
10
- class ObjectBinsize
11
-
12
- def measure(var, label: nil)
13
- dump(var, label: label)
14
- end
15
-
16
- def report(var, label: nil, padding: 10)
17
- file = measure(var, label: label)
18
-
19
- size = format_integer(file.size)
20
- name = label || File.basename(file.path)
21
- printf("%#{padding}s %s\n", size, name)
22
- end
23
-
24
- private
25
-
26
- def dump(var, **args)
27
- file = Tempfile.new(args[:label].to_s)
28
- file.write(Marshal.dump(var))
29
- file
30
- ensure
31
- file.close
32
- end
33
-
34
- def format_integer(int)
35
- int.to_s.reverse.gsub(/...(?=.)/, '\&,').reverse
36
- end
37
-
38
- end
39
-
40
- if __FILE__ == $0
41
- prof = ObjectBinsize.new
42
-
43
- prof.report(nil, label: "nil")
44
- prof.report(false, label: "false")
45
- prof.report(true, label: "true")
46
- prof.report(0, label: "integer")
47
- prof.report("", label: "empty string")
48
- prof.report({}, label: "empty hash")
49
- prof.report({}, label: "empty array")
50
-
51
- prof.report({ foo: "1" }, label: "hash 1 item (symbol)")
52
- prof.report({ foo: "1", bar: 2 }, label: "hash 2 items (symbol)")
53
- prof.report({ "foo" => "1" }, label: "hash 1 item (string)")
54
- prof.report({ "foo" => "1", "bar" => 2 }, label: "hash 2 items (string)")
55
-
56
- prof.report("big string" * 200, label: "big string * 200")
57
- end
data/test/psl_test.rb DELETED
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
- require "public_suffix"
5
-
6
- # This test runs against the current PSL file and ensures
7
- # the definitions satisfies the test suite.
8
- class PslTest < Minitest::Test
9
-
10
- ROOT = File.expand_path("..", __dir__)
11
-
12
- # rubocop:disable Security/Eval
13
- def self.tests
14
- File.readlines(File.join(ROOT, "test/tests.txt")).map do |line|
15
- line = line.strip
16
- next if line.empty?
17
- next if line.start_with?("//")
18
-
19
- input, output = line.split(", ")
20
-
21
- # handle the case of eval("null"), it must be eval("nil")
22
- input = "nil" if input == "null"
23
- output = "nil" if output == "null"
24
-
25
- input = eval(input)
26
- output = eval(output)
27
- [input, output]
28
- end
29
- end
30
- # rubocop:enable Security/Eval
31
-
32
-
33
- def test_valid
34
- # Parse the PSL and run the tests
35
- data = File.read(PublicSuffix::List::DEFAULT_LIST_PATH)
36
- PublicSuffix::List.default = PublicSuffix::List.parse(data)
37
-
38
- failures = []
39
- self.class.tests.each do |input, output|
40
- # Punycode domains are not supported ATM
41
- next if input =~ /xn--/
42
-
43
- domain = PublicSuffix.domain(input) rescue nil
44
- failures << [input, output, domain] if output != domain
45
- end
46
-
47
- message = "The following #{failures.size} tests fail:\n"
48
- failures.each { |i, o, d| message += format("Expected %s to be %s, got %s\n", i.inspect, o.inspect, d.inspect) }
49
- assert_equal 0, failures.size, message
50
- end
51
-
52
- end
data/test/test_helper.rb DELETED
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "minitest/autorun"
4
- require "minitest/reporters"
5
- require "mocha/minitest"
6
-
7
- Minitest::Reporters.use! Minitest::Reporters::DefaultReporter.new(color: true)
8
-
9
- $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
10
- require "public_suffix"