rtype-native 0.5.0 → 0.5.1
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.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/LICENSE +8 -8
- data/README.md +567 -567
- data/Rakefile +11 -11
- data/benchmark/benchmark.rb +191 -191
- data/ext/rtype/c/extconf.rb +2 -2
- data/ext/rtype/c/rtype.c +148 -148
- data/ext/rtype/c/rtype.h +4 -4
- data/spec/rtype_spec.rb +822 -822
- data/spec/spec_helper.rb +4 -4
- metadata +6 -5
data/Rakefile
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
require "rspec/core/rake_task"
|
2
|
-
|
3
|
-
# Default pattern is 'spec/**{,/*/**}/*_spec.rb'
|
4
|
-
RSpec::Core::RakeTask.new(:spec)
|
5
|
-
|
6
|
-
task :default => :spec
|
7
|
-
|
8
|
-
# Benchmark
|
9
|
-
desc "Compare with pure ruby and other gems"
|
10
|
-
task :benchmark do
|
11
|
-
ruby "benchmark/benchmark.rb"
|
1
|
+
require "rspec/core/rake_task"
|
2
|
+
|
3
|
+
# Default pattern is 'spec/**{,/*/**}/*_spec.rb'
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
|
6
|
+
task :default => :spec
|
7
|
+
|
8
|
+
# Benchmark
|
9
|
+
desc "Compare with pure ruby and other gems"
|
10
|
+
task :benchmark do
|
11
|
+
ruby "benchmark/benchmark.rb"
|
12
12
|
end
|
data/benchmark/benchmark.rb
CHANGED
@@ -1,192 +1,192 @@
|
|
1
|
-
require 'benchmark/ips'
|
2
|
-
|
3
|
-
is_mri = RUBY_ENGINE == 'ruby'
|
4
|
-
|
5
|
-
require "rtype"
|
6
|
-
require "rubype" if is_mri
|
7
|
-
require "sig"
|
8
|
-
require "contracts"
|
9
|
-
require "contracts/version"
|
10
|
-
require "typecheck"
|
11
|
-
|
12
|
-
puts "Ruby version: #{RUBY_VERSION}"
|
13
|
-
puts "Ruby engine: #{RUBY_ENGINE}"
|
14
|
-
puts "Ruby description: #{RUBY_DESCRIPTION}"
|
15
|
-
|
16
|
-
puts "Rtype version: #{Rtype::VERSION}"
|
17
|
-
puts "Rubype version: #{Rubype::VERSION}" if is_mri
|
18
|
-
puts "Sig version: #{Sig::VERSION}"
|
19
|
-
puts "Contracts version: #{Contracts::VERSION}"
|
20
|
-
puts "Typecheck version: #{Typecheck::VERSION}"
|
21
|
-
|
22
|
-
class PureTest
|
23
|
-
def sum(x, y)
|
24
|
-
x + y
|
25
|
-
end
|
26
|
-
|
27
|
-
def mul(x, y)
|
28
|
-
x * y
|
29
|
-
end
|
30
|
-
|
31
|
-
def args(a, b, c, d)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
pure_obj = PureTest.new
|
35
|
-
|
36
|
-
class RtypeTest
|
37
|
-
rtype [Numeric, Numeric] => Numeric
|
38
|
-
def sum(x, y)
|
39
|
-
x + y
|
40
|
-
end
|
41
|
-
|
42
|
-
rtype [:to_i, :to_i] => Numeric
|
43
|
-
def mul(x, y)
|
44
|
-
x * y
|
45
|
-
end
|
46
|
-
|
47
|
-
rtype [Integer, Numeric, String, :to_i] => Any
|
48
|
-
def args(a, b, c, d)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
rtype_obj = RtypeTest.new
|
52
|
-
|
53
|
-
if is_mri
|
54
|
-
class RubypeTest
|
55
|
-
def sum(x, y)
|
56
|
-
x + y
|
57
|
-
end
|
58
|
-
typesig :sum, [Numeric, Numeric] => Numeric
|
59
|
-
|
60
|
-
def mul(x, y)
|
61
|
-
x * y
|
62
|
-
end
|
63
|
-
typesig :mul, [:to_i, :to_i] => Numeric
|
64
|
-
|
65
|
-
def args(a, b, c, d)
|
66
|
-
end
|
67
|
-
typesig :args, [Integer, Numeric, String, :to_i] => Any
|
68
|
-
end
|
69
|
-
rubype_obj = RubypeTest.new
|
70
|
-
end
|
71
|
-
|
72
|
-
class SigTest
|
73
|
-
sig [Numeric, Numeric], Numeric,
|
74
|
-
def sum(x, y)
|
75
|
-
x + y
|
76
|
-
end
|
77
|
-
|
78
|
-
sig [:to_i, :to_i], Numeric,
|
79
|
-
def mul(x, y)
|
80
|
-
x * y
|
81
|
-
end
|
82
|
-
|
83
|
-
# nil means wildcard
|
84
|
-
sig [Integer, Numeric, String, :to_i], nil,
|
85
|
-
def args(a, b, c, d)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
sig_obj = SigTest.new
|
89
|
-
|
90
|
-
class ContractsTest
|
91
|
-
include Contracts
|
92
|
-
|
93
|
-
Contract Num, Num => Num
|
94
|
-
def sum(x, y)
|
95
|
-
x + y
|
96
|
-
end
|
97
|
-
|
98
|
-
Contract RespondTo[:to_i], RespondTo[:to_i] => Num
|
99
|
-
def mul(x, y)
|
100
|
-
x * y
|
101
|
-
end
|
102
|
-
|
103
|
-
Contract Int, Num, String, RespondTo[:to_i] => Any
|
104
|
-
def args(a, b, c, d)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
contracts_obj = ContractsTest.new
|
108
|
-
|
109
|
-
class TypecheckTest
|
110
|
-
extend Typecheck
|
111
|
-
|
112
|
-
typecheck 'Numeric, Numeric -> Numeric',
|
113
|
-
def sum(x, y)
|
114
|
-
x + y
|
115
|
-
end
|
116
|
-
|
117
|
-
typecheck '#to_i, #to_i -> Numeric',
|
118
|
-
def mul(x, y)
|
119
|
-
x * y
|
120
|
-
end
|
121
|
-
|
122
|
-
typecheck 'Integer, Numeric, String, #to_i -> BasicObject',
|
123
|
-
def args(a, b, c, d)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
typecheck_obj = TypecheckTest.new
|
127
|
-
|
128
|
-
Benchmark.ips do |x|
|
129
|
-
x.report("pure") do |times|
|
130
|
-
i = 0
|
131
|
-
while i < times
|
132
|
-
pure_obj.sum(1, 2)
|
133
|
-
pure_obj.mul(1, 2)
|
134
|
-
pure_obj.args(1, 2, "c", 4)
|
135
|
-
i += 1
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
x.report("rtype") do |times|
|
140
|
-
i = 0
|
141
|
-
while i < times
|
142
|
-
rtype_obj.sum(1, 2)
|
143
|
-
rtype_obj.mul(1, 2)
|
144
|
-
rtype_obj.args(1, 2, "c", 4)
|
145
|
-
i += 1
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
if is_mri
|
150
|
-
x.report("rubype") do |times|
|
151
|
-
i = 0
|
152
|
-
while i < times
|
153
|
-
rubype_obj.sum(1, 2)
|
154
|
-
rubype_obj.mul(1, 2)
|
155
|
-
rubype_obj.args(1, 2, "c", 4)
|
156
|
-
i += 1
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
x.report("sig") do |times|
|
162
|
-
i = 0
|
163
|
-
while i < times
|
164
|
-
sig_obj.sum(1, 2)
|
165
|
-
sig_obj.mul(1, 2)
|
166
|
-
sig_obj.args(1, 2, "c", 4)
|
167
|
-
i += 1
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
x.report("contracts") do |times|
|
172
|
-
i = 0
|
173
|
-
while i < times
|
174
|
-
contracts_obj.sum(1, 2)
|
175
|
-
contracts_obj.mul(1, 2)
|
176
|
-
contracts_obj.args(1, 2, "c", 4)
|
177
|
-
i += 1
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
x.report("typecheck") do |times|
|
182
|
-
i = 0
|
183
|
-
while i < times
|
184
|
-
typecheck_obj.sum(1, 2)
|
185
|
-
typecheck_obj.mul(1, 2)
|
186
|
-
typecheck_obj.args(1, 2, "c", 4)
|
187
|
-
i += 1
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
x.compare!
|
1
|
+
require 'benchmark/ips'
|
2
|
+
|
3
|
+
is_mri = RUBY_ENGINE == 'ruby'
|
4
|
+
|
5
|
+
require "rtype"
|
6
|
+
require "rubype" if is_mri
|
7
|
+
require "sig"
|
8
|
+
require "contracts"
|
9
|
+
require "contracts/version"
|
10
|
+
require "typecheck"
|
11
|
+
|
12
|
+
puts "Ruby version: #{RUBY_VERSION}"
|
13
|
+
puts "Ruby engine: #{RUBY_ENGINE}"
|
14
|
+
puts "Ruby description: #{RUBY_DESCRIPTION}"
|
15
|
+
|
16
|
+
puts "Rtype version: #{Rtype::VERSION}"
|
17
|
+
puts "Rubype version: #{Rubype::VERSION}" if is_mri
|
18
|
+
puts "Sig version: #{Sig::VERSION}"
|
19
|
+
puts "Contracts version: #{Contracts::VERSION}"
|
20
|
+
puts "Typecheck version: #{Typecheck::VERSION}"
|
21
|
+
|
22
|
+
class PureTest
|
23
|
+
def sum(x, y)
|
24
|
+
x + y
|
25
|
+
end
|
26
|
+
|
27
|
+
def mul(x, y)
|
28
|
+
x * y
|
29
|
+
end
|
30
|
+
|
31
|
+
def args(a, b, c, d)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
pure_obj = PureTest.new
|
35
|
+
|
36
|
+
class RtypeTest
|
37
|
+
rtype [Numeric, Numeric] => Numeric
|
38
|
+
def sum(x, y)
|
39
|
+
x + y
|
40
|
+
end
|
41
|
+
|
42
|
+
rtype [:to_i, :to_i] => Numeric
|
43
|
+
def mul(x, y)
|
44
|
+
x * y
|
45
|
+
end
|
46
|
+
|
47
|
+
rtype [Integer, Numeric, String, :to_i] => Any
|
48
|
+
def args(a, b, c, d)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
rtype_obj = RtypeTest.new
|
52
|
+
|
53
|
+
if is_mri
|
54
|
+
class RubypeTest
|
55
|
+
def sum(x, y)
|
56
|
+
x + y
|
57
|
+
end
|
58
|
+
typesig :sum, [Numeric, Numeric] => Numeric
|
59
|
+
|
60
|
+
def mul(x, y)
|
61
|
+
x * y
|
62
|
+
end
|
63
|
+
typesig :mul, [:to_i, :to_i] => Numeric
|
64
|
+
|
65
|
+
def args(a, b, c, d)
|
66
|
+
end
|
67
|
+
typesig :args, [Integer, Numeric, String, :to_i] => Any
|
68
|
+
end
|
69
|
+
rubype_obj = RubypeTest.new
|
70
|
+
end
|
71
|
+
|
72
|
+
class SigTest
|
73
|
+
sig [Numeric, Numeric], Numeric,
|
74
|
+
def sum(x, y)
|
75
|
+
x + y
|
76
|
+
end
|
77
|
+
|
78
|
+
sig [:to_i, :to_i], Numeric,
|
79
|
+
def mul(x, y)
|
80
|
+
x * y
|
81
|
+
end
|
82
|
+
|
83
|
+
# nil means wildcard
|
84
|
+
sig [Integer, Numeric, String, :to_i], nil,
|
85
|
+
def args(a, b, c, d)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
sig_obj = SigTest.new
|
89
|
+
|
90
|
+
class ContractsTest
|
91
|
+
include Contracts
|
92
|
+
|
93
|
+
Contract Num, Num => Num
|
94
|
+
def sum(x, y)
|
95
|
+
x + y
|
96
|
+
end
|
97
|
+
|
98
|
+
Contract RespondTo[:to_i], RespondTo[:to_i] => Num
|
99
|
+
def mul(x, y)
|
100
|
+
x * y
|
101
|
+
end
|
102
|
+
|
103
|
+
Contract Int, Num, String, RespondTo[:to_i] => Any
|
104
|
+
def args(a, b, c, d)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
contracts_obj = ContractsTest.new
|
108
|
+
|
109
|
+
class TypecheckTest
|
110
|
+
extend Typecheck
|
111
|
+
|
112
|
+
typecheck 'Numeric, Numeric -> Numeric',
|
113
|
+
def sum(x, y)
|
114
|
+
x + y
|
115
|
+
end
|
116
|
+
|
117
|
+
typecheck '#to_i, #to_i -> Numeric',
|
118
|
+
def mul(x, y)
|
119
|
+
x * y
|
120
|
+
end
|
121
|
+
|
122
|
+
typecheck 'Integer, Numeric, String, #to_i -> BasicObject',
|
123
|
+
def args(a, b, c, d)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
typecheck_obj = TypecheckTest.new
|
127
|
+
|
128
|
+
Benchmark.ips do |x|
|
129
|
+
x.report("pure") do |times|
|
130
|
+
i = 0
|
131
|
+
while i < times
|
132
|
+
pure_obj.sum(1, 2)
|
133
|
+
pure_obj.mul(1, 2)
|
134
|
+
pure_obj.args(1, 2, "c", 4)
|
135
|
+
i += 1
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
x.report("rtype") do |times|
|
140
|
+
i = 0
|
141
|
+
while i < times
|
142
|
+
rtype_obj.sum(1, 2)
|
143
|
+
rtype_obj.mul(1, 2)
|
144
|
+
rtype_obj.args(1, 2, "c", 4)
|
145
|
+
i += 1
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
if is_mri
|
150
|
+
x.report("rubype") do |times|
|
151
|
+
i = 0
|
152
|
+
while i < times
|
153
|
+
rubype_obj.sum(1, 2)
|
154
|
+
rubype_obj.mul(1, 2)
|
155
|
+
rubype_obj.args(1, 2, "c", 4)
|
156
|
+
i += 1
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
x.report("sig") do |times|
|
162
|
+
i = 0
|
163
|
+
while i < times
|
164
|
+
sig_obj.sum(1, 2)
|
165
|
+
sig_obj.mul(1, 2)
|
166
|
+
sig_obj.args(1, 2, "c", 4)
|
167
|
+
i += 1
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
x.report("contracts") do |times|
|
172
|
+
i = 0
|
173
|
+
while i < times
|
174
|
+
contracts_obj.sum(1, 2)
|
175
|
+
contracts_obj.mul(1, 2)
|
176
|
+
contracts_obj.args(1, 2, "c", 4)
|
177
|
+
i += 1
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
x.report("typecheck") do |times|
|
182
|
+
i = 0
|
183
|
+
while i < times
|
184
|
+
typecheck_obj.sum(1, 2)
|
185
|
+
typecheck_obj.mul(1, 2)
|
186
|
+
typecheck_obj.args(1, 2, "c", 4)
|
187
|
+
i += 1
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
x.compare!
|
192
192
|
end
|
data/ext/rtype/c/extconf.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
require 'mkmf'
|
2
|
-
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
3
|
create_makefile("rtype/rtype_native")
|