ipconverter 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/Rakefile +8 -0
- data/benchmark/int_to_str.rb +3 -3
- data/benchmark/str_to_int.rb +7 -6
- data/ext/ipconverter/ipconverter.c +5 -5
- data/ipconverter.gemspec +3 -2
- data/lib/ipconverter/version.rb +1 -1
- data/test/test_ipconverter.rb +4 -5
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb58eea08d7c5c456e4e104201be99be367d3001
|
4
|
+
data.tar.gz: 99fef017ef4f71cfde3b8f7c0e210e3e48878abe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b37510036d6ca814507b484fc505e3de596f9eea574828f94be0faf6ee54a7bb0a2971d54d5803bd9d955b894e627cdbf5d162621a99aebe63f113390af1d78
|
7
|
+
data.tar.gz: 0bae9046ceed9f63c5de6ee3259f9fce79b291832bf55bb224ec29b7c67045f68ecaa7df36bdc4c0e13988b650211db6f2c334c8327f322c5f1ad5d866af5d98
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
lib/**/*.rb ext/**/*.c README
|
data/Rakefile
CHANGED
@@ -2,6 +2,8 @@ require 'bundler/gem_tasks'
|
|
2
2
|
require 'rake/testtask'
|
3
3
|
require 'rake/extensiontask'
|
4
4
|
|
5
|
+
ROOT = File.expand_path('..', __FILE__)
|
6
|
+
|
5
7
|
Rake::TestTask.new do |t|
|
6
8
|
t.libs << 'test'
|
7
9
|
t.pattern = 'test/test_*.rb'
|
@@ -12,3 +14,9 @@ Rake::ExtensionTask.new 'ipconverter' do |ext|
|
|
12
14
|
end
|
13
15
|
|
14
16
|
task default: [:compile, :test]
|
17
|
+
|
18
|
+
desc "Run benchmarks"
|
19
|
+
task benchmark: [:compile] do
|
20
|
+
sh "ruby #{ROOT}/benchmark/str_to_int.rb"
|
21
|
+
sh "ruby #{ROOT}/benchmark/int_to_str.rb"
|
22
|
+
end
|
data/benchmark/int_to_str.rb
CHANGED
@@ -2,7 +2,7 @@ require 'benchmark'
|
|
2
2
|
require 'ipaddr'
|
3
3
|
require 'ipconverter'
|
4
4
|
|
5
|
-
def ruby_shift(ip)
|
5
|
+
def self.ruby_shift(ip)
|
6
6
|
[
|
7
7
|
(ip >> 24) & 255,
|
8
8
|
(ip >> 16) & 255,
|
@@ -11,13 +11,13 @@ def ruby_shift(ip)
|
|
11
11
|
].join('.')
|
12
12
|
end
|
13
13
|
|
14
|
-
ips = 0..
|
14
|
+
ips = 0..999_999
|
15
15
|
|
16
16
|
puts 'iterations: 1,000,000'
|
17
17
|
|
18
18
|
Benchmark.bmbm do |x|
|
19
19
|
x.report('IPAddr#to_s') { ips.each { |ip| IPAddr.new(ip, Socket::AF_INET).to_s } }
|
20
20
|
x.report('Ruby shifts') { ips.each { |ip| ruby_shift(ip) } }
|
21
|
-
x.report('
|
21
|
+
x.report('IpConverter') { ips.each { |ip| IpConverter.int_to_str(ip) } }
|
22
22
|
x.report('noop') { ips.each { |ip| ip } }
|
23
23
|
end
|
data/benchmark/str_to_int.rb
CHANGED
@@ -2,11 +2,12 @@ require 'benchmark'
|
|
2
2
|
require 'ipaddr'
|
3
3
|
require 'ipconverter'
|
4
4
|
|
5
|
-
def
|
5
|
+
def self.pack_unpack(ip)
|
6
6
|
ip.split('.').collect(&:to_i).pack('C*').unpack('N').first
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
# rubocop:disable AbcSize
|
10
|
+
def self.split_multiply(ip)
|
10
11
|
octets = ip.split('.').map(&:to_i)
|
11
12
|
octets[3] +
|
12
13
|
octets[2] * 256 +
|
@@ -14,7 +15,7 @@ def ip_to_i2(ip)
|
|
14
15
|
octets[0] * 256 * 256 * 256
|
15
16
|
end
|
16
17
|
|
17
|
-
def ipaddr_to_i(ip)
|
18
|
+
def self.ipaddr_to_i(ip)
|
18
19
|
IPAddr.new(ip).to_i
|
19
20
|
end
|
20
21
|
|
@@ -33,8 +34,8 @@ puts 'iterations: 1,000,000'
|
|
33
34
|
|
34
35
|
Benchmark.bmbm do |x|
|
35
36
|
x.report('IPAddr#to_i') { ips.each { |ip| IPAddr.new(ip).to_i } }
|
36
|
-
x.report('pack/unpack') { ips.each { |ip|
|
37
|
-
x.report('split/multiply') { ips.each { |ip|
|
38
|
-
x.report('
|
37
|
+
x.report('pack/unpack') { ips.each { |ip| pack_unpack(ip) } }
|
38
|
+
x.report('split/multiply') { ips.each { |ip| split_multiply(ip) } }
|
39
|
+
x.report('IpConverter') { ips.each { |ip| IpConverter.str_to_int(ip) } }
|
39
40
|
x.report('noop') { ips.each { |ip| ip } }
|
40
41
|
end
|
@@ -14,9 +14,9 @@ void Init_ipconverter() {
|
|
14
14
|
|
15
15
|
/*
|
16
16
|
* call-seq:
|
17
|
-
* IpConverter.str_to_int(ip_addr_string) ->
|
17
|
+
* IpConverter.str_to_int(ip_addr_string) -> Integer
|
18
18
|
*
|
19
|
-
* Converts the passed IP address String into
|
19
|
+
* Converts the passed IP address String into an Integer.
|
20
20
|
*
|
21
21
|
* Raises ArgumentError if ip address is not valid. Leading and trailing
|
22
22
|
* whitespace is ignored.
|
@@ -36,7 +36,7 @@ VALUE method_str_to_int(VALUE _module_, VALUE ip_string) {
|
|
36
36
|
int success = ip_string_to_long(c_string, &result);
|
37
37
|
|
38
38
|
if (success) {
|
39
|
-
// Convert the uint32_t back to a ruby
|
39
|
+
// Convert the uint32_t back to a ruby Integer.
|
40
40
|
return UINT2NUM(result);
|
41
41
|
} else {
|
42
42
|
rb_raise(rb_eArgError, "Invalid IP Address String");
|
@@ -86,9 +86,9 @@ ip_string_to_long(char c_string[], uint32_t *result) {
|
|
86
86
|
*
|
87
87
|
*/
|
88
88
|
VALUE
|
89
|
-
method_int_to_str(VALUE _module_, VALUE
|
89
|
+
method_int_to_str(VALUE _module_, VALUE ip_integer) {
|
90
90
|
char c_string[16];
|
91
|
-
int64_t ip = NUM2LL(
|
91
|
+
int64_t ip = NUM2LL(ip_integer);
|
92
92
|
if (ip > MAX_IP_INT || ip < 0) {
|
93
93
|
rb_raise(rb_eArgError, "IP address integer out of range");
|
94
94
|
}
|
data/ipconverter.gemspec
CHANGED
@@ -11,8 +11,8 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.authors = ['Joshua Scott']
|
12
12
|
spec.email = ['joshua.scott@gmail.com']
|
13
13
|
spec.summary = 'Utilities for working with IP addresses'
|
14
|
-
spec.description =
|
15
|
-
string to integer
|
14
|
+
spec.description = 'Fast C extension for converting IP addresses from
|
15
|
+
string to integer'
|
16
16
|
spec.homepage = 'http://github.com/joshuawscott/ipconverter'
|
17
17
|
spec.license = 'MIT'
|
18
18
|
|
@@ -26,4 +26,5 @@ string to integer)
|
|
26
26
|
spec.add_development_dependency 'rake', '~> 10'
|
27
27
|
spec.add_development_dependency 'minitest', '~> 5'
|
28
28
|
spec.add_development_dependency 'rake-compiler', '~> 0.9'
|
29
|
+
spec.add_development_dependency 'rubocop', '~> 0.47'
|
29
30
|
end
|
data/lib/ipconverter/version.rb
CHANGED
data/test/test_ipconverter.rb
CHANGED
@@ -2,9 +2,8 @@ require 'ipconverter'
|
|
2
2
|
require 'minitest/autorun'
|
3
3
|
|
4
4
|
class TestIpConverter < MiniTest::Test
|
5
|
-
MAX_IP_INT =
|
6
|
-
def setup
|
7
|
-
end
|
5
|
+
MAX_IP_INT = 4_294_967_295
|
6
|
+
def setup; end
|
8
7
|
|
9
8
|
def test_smallest_ip
|
10
9
|
int = IpConverter.str_to_int '0.0.0.0'
|
@@ -43,11 +42,11 @@ class TestIpConverter < MiniTest::Test
|
|
43
42
|
end
|
44
43
|
|
45
44
|
def test_int_to_str_max
|
46
|
-
assert_equal "255.255.255.255", IpConverter.int_to_str(MAX_IP_INT)
|
45
|
+
assert_equal "255.255.255.255", IpConverter.int_to_str(MAX_IP_INT)
|
47
46
|
end
|
48
47
|
|
49
48
|
def test_int_to_str_negative
|
50
|
-
assert_raises(ArgumentError) { IpConverter.int_to_str
|
49
|
+
assert_raises(ArgumentError) { IpConverter.int_to_str(-1) }
|
51
50
|
end
|
52
51
|
|
53
52
|
def test_int_to_str_too_big
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ipconverter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Scott
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.47'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.47'
|
69
83
|
description: |-
|
70
84
|
Fast C extension for converting IP addresses from
|
71
85
|
string to integer
|
@@ -77,6 +91,7 @@ extensions:
|
|
77
91
|
extra_rdoc_files: []
|
78
92
|
files:
|
79
93
|
- ".gitignore"
|
94
|
+
- ".yardopts"
|
80
95
|
- Gemfile
|
81
96
|
- LICENSE.txt
|
82
97
|
- README.md
|
@@ -111,10 +126,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
126
|
version: '0'
|
112
127
|
requirements: []
|
113
128
|
rubyforge_project:
|
114
|
-
rubygems_version: 2.
|
129
|
+
rubygems_version: 2.6.8
|
115
130
|
signing_key:
|
116
131
|
specification_version: 4
|
117
132
|
summary: Utilities for working with IP addresses
|
118
133
|
test_files:
|
119
134
|
- test/test_ipconverter.rb
|
120
|
-
has_rdoc:
|