-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathRakefile
57 lines (47 loc) · 1.13 KB
/
Rakefile
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
require "bundler/gem_tasks"
require "rake/testtask"
require "rake/extensiontask"
# Test
#-----------------------------------------------
Rake::TestTask.new(:test) do |t|
t.libs << "test"
end
# Compile C extension
#-----------------------------------------------
Rake::ExtensionTask.new("rubype") do |ext|
ext.lib_dir = "lib/rubype"
end
task :compile_and_test do
Rake::Task['compile'].invoke
Rake::Task['test'].invoke
end
# Benchmark
#-----------------------------------------------
desc "Compare with pure ruby"
task :benchmark do
require "benchmark/ips"
require "rubype"
require "rubype/version"
puts "ruby version: #{RUBY_VERSION}"
class PureClass
def sum(x, y)
x + y
end
end
pure_instance = PureClass.new
puts "rubype version: #{Rubype::VERSION}"
class RubypeClass
def sum(x, y)
x + y
end
typesig :sum, [Numeric, Numeric] => Numeric
end
rubype_instance = RubypeClass.new
Benchmark.ips do |x|
x.report('Pure Ruby') { pure_instance.sum(4, 2) }
x.report('Rubype') { rubype_instance.sum(4, 2) }
x.compare!
end
end
task bm: :benchmark
task default: :compile_and_test