public_suffix 5.0.1 → 5.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +19 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +9 -2
  5. data/SECURITY.md +2 -81
  6. data/data/list.txt +3062 -1820
  7. data/lib/public_suffix/domain.rb +1 -1
  8. data/lib/public_suffix/errors.rb +1 -1
  9. data/lib/public_suffix/list.rb +1 -1
  10. data/lib/public_suffix/rule.rb +1 -1
  11. data/lib/public_suffix/version.rb +3 -4
  12. data/lib/public_suffix.rb +1 -1
  13. metadata +8 -42
  14. data/.github/FUNDING.yml +0 -12
  15. data/.github/dependabot.yml +0 -19
  16. data/.github/workflows/psl-update.yml +0 -38
  17. data/.github/workflows/release.yml +0 -18
  18. data/.github/workflows/tests.yml +0 -29
  19. data/.gitignore +0 -8
  20. data/.rubocop.yml +0 -37
  21. data/.rubocop_opinionated.yml +0 -135
  22. data/Gemfile +0 -14
  23. data/Rakefile +0 -52
  24. data/bin/console +0 -15
  25. data/public_suffix.gemspec +0 -29
  26. data/test/.empty +0 -2
  27. data/test/acceptance_test.rb +0 -131
  28. data/test/benchmarks/bm_find.rb +0 -66
  29. data/test/benchmarks/bm_find_all.rb +0 -102
  30. data/test/benchmarks/bm_names.rb +0 -91
  31. data/test/benchmarks/bm_select.rb +0 -26
  32. data/test/benchmarks/bm_select_incremental.rb +0 -25
  33. data/test/benchmarks/bm_valid.rb +0 -101
  34. data/test/profilers/domain_profiler.rb +0 -12
  35. data/test/profilers/find_profiler.rb +0 -12
  36. data/test/profilers/find_profiler_jp.rb +0 -12
  37. data/test/profilers/initialization_profiler.rb +0 -11
  38. data/test/profilers/list_profsize.rb +0 -11
  39. data/test/profilers/object_binsize.rb +0 -57
  40. data/test/psl_test.rb +0 -52
  41. data/test/test_helper.rb +0 -10
  42. data/test/tests.txt +0 -98
  43. data/test/unit/domain_test.rb +0 -106
  44. data/test/unit/errors_test.rb +0 -25
  45. data/test/unit/list_test.rb +0 -241
  46. data/test/unit/public_suffix_test.rb +0 -188
  47. data/test/unit/rule_test.rb +0 -222
@@ -1,131 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class AcceptanceTest < Minitest::Test
6
-
7
- VALID_CASES = [
8
- ["example.com", "example.com", [nil, "example", "com"]],
9
- ["foo.example.com", "example.com", ["foo", "example", "com"]],
10
-
11
- ["verybritish.co.uk", "verybritish.co.uk", [nil, "verybritish", "co.uk"]],
12
- ["foo.verybritish.co.uk", "verybritish.co.uk", ["foo", "verybritish", "co.uk"]],
13
-
14
- ["parliament.uk", "parliament.uk", [nil, "parliament", "uk"]],
15
- ["foo.parliament.uk", "parliament.uk", ["foo", "parliament", "uk"]],
16
- ].freeze
17
-
18
- def test_valid
19
- VALID_CASES.each do |input, domain, results|
20
- parsed = PublicSuffix.parse(input)
21
- trd, sld, tld = results
22
- assert_equal tld, parsed.tld, "Invalid tld for `#{name}`"
23
- assert_equal sld, parsed.sld, "Invalid sld for `#{name}`"
24
- if trd.nil?
25
- assert_nil parsed.trd, "Invalid trd for `#{name}`"
26
- else
27
- assert_equal trd, parsed.trd, "Invalid trd for `#{name}`"
28
- end
29
-
30
- assert_equal domain, PublicSuffix.domain(input)
31
- assert PublicSuffix.valid?(input)
32
- end
33
- end
34
-
35
-
36
- INVALID_CASES = [
37
- ["nic.bd", PublicSuffix::DomainNotAllowed],
38
- [nil, PublicSuffix::DomainInvalid],
39
- ["", PublicSuffix::DomainInvalid],
40
- [" ", PublicSuffix::DomainInvalid],
41
- ].freeze
42
-
43
- def test_invalid
44
- INVALID_CASES.each do |(name, error)|
45
- assert_raises(error) { PublicSuffix.parse(name) }
46
- assert !PublicSuffix.valid?(name)
47
- end
48
- end
49
-
50
-
51
- REJECTED_CASES = [
52
- ["www. .com", true],
53
- ["foo.co..uk", true],
54
- ["goo,gle.com", true],
55
- ["-google.com", true],
56
- ["google-.com", true],
57
-
58
- # This case was covered in GH-15.
59
- # I decided to cover this case because it's not easily reproducible with URI.parse
60
- # and can lead to several false positives.
61
- ["http://google.com", false],
62
- ].freeze
63
-
64
- def test_rejected
65
- REJECTED_CASES.each do |name, expected|
66
- assert_equal expected, PublicSuffix.valid?(name),
67
- format("Expected %s to be %s", name.inspect, expected.inspect)
68
- assert !valid_domain?(name),
69
- "#{name} expected to be invalid"
70
- end
71
- end
72
-
73
-
74
- CASE_CASES = [
75
- ["Www.google.com", %w[www google com]],
76
- ["www.Google.com", %w[www google com]],
77
- ["www.google.Com", %w[www google com]],
78
- ].freeze
79
-
80
- def test_ignore_case
81
- CASE_CASES.each do |name, results|
82
- domain = PublicSuffix.parse(name)
83
- trd, sld, tld = results
84
- assert_equal tld, domain.tld, "Invalid tld for `#{name}'"
85
- assert_equal sld, domain.sld, "Invalid sld for `#{name}'"
86
- assert_equal trd, domain.trd, "Invalid trd for `#{name}'"
87
- assert PublicSuffix.valid?(name)
88
- end
89
- end
90
-
91
-
92
- INCLUDE_PRIVATE_CASES = [
93
- ["blogspot.com", true, "blogspot.com"],
94
- ["blogspot.com", false, nil],
95
- ["subdomain.blogspot.com", true, "blogspot.com"],
96
- ["subdomain.blogspot.com", false, "subdomain.blogspot.com"],
97
- ].freeze
98
-
99
- # rubocop:disable Style/CombinableLoops
100
- def test_ignore_private
101
- # test domain and parse
102
- INCLUDE_PRIVATE_CASES.each do |given, ignore_private, expected|
103
- if expected.nil?
104
- assert_nil PublicSuffix.domain(given, ignore_private: ignore_private)
105
- else
106
- assert_equal expected, PublicSuffix.domain(given, ignore_private: ignore_private)
107
- end
108
- end
109
- # test valid?
110
- INCLUDE_PRIVATE_CASES.each do |given, ignore_private, expected|
111
- assert_equal !expected.nil?, PublicSuffix.valid?(given, ignore_private: ignore_private)
112
- end
113
- end
114
- # rubocop:enable Style/CombinableLoops
115
-
116
-
117
- def valid_uri?(name)
118
- uri = URI.parse(name)
119
- !uri.host.nil?
120
- rescue StandardError
121
- false
122
- end
123
-
124
- def valid_domain?(name)
125
- uri = URI.parse(name)
126
- !uri.host.nil? && uri.scheme.nil?
127
- rescue StandardError
128
- false
129
- end
130
-
131
- end
@@ -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