fastruby 0.0.17 → 0.0.18

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 (67) hide show
  1. data/CHANGELOG +10 -0
  2. data/Rakefile +4 -2
  3. data/benchmarks/benchmark.rb +20 -44
  4. data/benchmarks/benchmark.rb~ +47 -0
  5. data/benchmarks/benchmark2.rb +19 -45
  6. data/benchmarks/benchmark2.rb~ +46 -0
  7. data/benchmarks/benchmark3.rb +19 -45
  8. data/benchmarks/benchmark3.rb~ +46 -0
  9. data/benchmarks/benchmark4.rb +30 -65
  10. data/benchmarks/benchmark4.rb~ +61 -0
  11. data/benchmarks/benchmark5.rb +25 -55
  12. data/benchmarks/benchmark5.rb~ +54 -0
  13. data/benchmarks/benchmark6.rb +19 -40
  14. data/benchmarks/benchmark6.rb~ +41 -0
  15. data/benchmarks/benchmark7.rb +23 -52
  16. data/benchmarks/benchmark7.rb~ +48 -0
  17. data/ext/fastruby_base/fastruby_base.inl +1 -0
  18. data/lib/fastruby/builder.rb +128 -76
  19. data/lib/fastruby/cache/cache.rb +9 -5
  20. data/lib/fastruby/fastruby_sexp.rb +18 -0
  21. data/lib/fastruby/inliner/inliner.rb +68 -0
  22. data/lib/fastruby/inliner/modules/call.rb +150 -0
  23. data/lib/fastruby/inliner/modules/recursive.rb +35 -0
  24. data/lib/fastruby/object.rb +17 -32
  25. data/lib/fastruby/reductor/modules/case.rb +49 -0
  26. data/lib/{fastruby.rb~ → fastruby/reductor/modules/for.rb} +11 -13
  27. data/lib/fastruby/reductor/modules/nontree.rb +31 -0
  28. data/lib/fastruby/reductor/modules/recursive.rb +31 -0
  29. data/lib/fastruby/reductor/reductor.rb +39 -0
  30. data/lib/fastruby/set_tree.rb +7 -1
  31. data/lib/fastruby/sexp_extension.rb +6 -0
  32. data/lib/fastruby/translator/modules/block.rb +4 -4
  33. data/lib/fastruby/translator/modules/call.rb +9 -26
  34. data/lib/fastruby/translator/modules/defn.rb +5 -3
  35. data/lib/fastruby/translator/modules/directive.rb +42 -0
  36. data/lib/fastruby/translator/modules/exceptions.rb +12 -30
  37. data/lib/fastruby/translator/modules/flow.rb +33 -83
  38. data/lib/fastruby/translator/modules/iter.rb +4 -7
  39. data/lib/fastruby/translator/modules/literal.rb +11 -25
  40. data/lib/fastruby/translator/modules/logical.rb +5 -3
  41. data/lib/fastruby/translator/modules/method_group.rb +4 -3
  42. data/lib/fastruby/translator/modules/nonlocal.rb +7 -5
  43. data/lib/fastruby/translator/modules/static.rb +242 -0
  44. data/lib/fastruby/translator/modules/variable.rb +16 -9
  45. data/lib/fastruby/translator/scope_mode_helper.rb +2 -27
  46. data/lib/fastruby/translator/translator.rb +131 -60
  47. data/lib/fastruby/translator/translator_modules.rb +6 -2
  48. data/lib/fastruby.rb +1 -1
  49. data/spec/reductor/base_spec.rb +46 -0
  50. data/spec/ruby/base_spec.rb~ +394 -0
  51. data/spec/ruby/block/arguments_spec.rb~ +214 -0
  52. data/spec/ruby/block/proc_as_block_spec.rb~ +23 -0
  53. data/spec/ruby/block/retry_spec.rb~ +43 -0
  54. data/spec/ruby/block_spec.rb~ +520 -0
  55. data/spec/ruby/defn/replacement_spec.rb~ +102 -0
  56. data/spec/ruby/integrity_spec.rb~ +40 -0
  57. data/spec/ruby/singleton_spec.rb~ +76 -0
  58. data/spec/scope_mode/base_spec.rb +14 -5
  59. data/spec/scope_mode/block_spec.rb +18 -9
  60. data/spec/scope_mode/call_spec.rb +11 -2
  61. data/spec/scope_mode/exception_spec.rb +11 -2
  62. data/spec/scope_mode/flow_spec.rb +18 -8
  63. data/spec/scope_mode/optimization_spec.rb +21 -13
  64. data/spec/static/base_spec.rb +54 -0
  65. data/spec/static/flow_spec.rb +48 -0
  66. data/spec/static/operator_spec.rb +104 -0
  67. metadata +58 -8
data/CHANGELOG CHANGED
@@ -1,3 +1,13 @@
1
+ 0.0.18 Optimize of exising methods using "optimize" (only pure ruby methods are supported)
2
+
3
+ Implemented new cache by syntax tree, more accurate, fixing a few cache bugs and compatible with inlining
4
+
5
+ Removed all cache by code string, buggy by design
6
+
7
+ performance: Implemented inlining of method calls (not iter call supported, splat calls nor inline of methods with iter calls)
8
+
9
+ Internal refactor: Changed C translator to use chain of responsability (define_method_handler dependency on Rakefile)
10
+
1
11
  0.0.17 Fixed bug of non-volatile variables on scopes calling setjmp
2
12
 
3
13
  Fixed bug of native pointers encoding on 32 bits systems
data/Rakefile CHANGED
@@ -7,14 +7,16 @@ require "rspec/core/rake_task"
7
7
 
8
8
  spec = Gem::Specification.new do |s|
9
9
  s.name = 'fastruby'
10
- s.version = '0.0.17'
10
+ s.version = '0.0.18'
11
11
  s.author = 'Dario Seminara'
12
12
  s.email = 'robertodarioseminara@gmail.com'
13
13
  s.platform = Gem::Platform::RUBY
14
14
  s.summary = 'fast execution of ruby code'
15
15
  s.homepage = "http://github.com/tario/fastruby"
16
16
  s.add_dependency "RubyInline", "= 3.11.0"
17
- s.add_dependency "ruby_parser", "= 2.0.6"
17
+ s.add_dependency "ruby_parser", ">= 2.0.6"
18
+ s.add_dependency "define_method_handler", ">= 0.0.5"
19
+ s.add_dependency "method_source", ">= 0.6.7"
18
20
  s.has_rdoc = true
19
21
  s.extra_rdoc_files = [ 'README' ]
20
22
  s.extensions = FileList["ext/**/extconf.rb"].to_a
@@ -2,68 +2,44 @@ require "rubygems"
2
2
  require "fastruby"
3
3
 
4
4
  class X
5
- fastruby "
6
- def foo(a,b)
7
- return a+b
8
- end
9
- "
5
+ def foo(a,b)
6
+ return a+b
7
+ end
10
8
  end
11
9
 
12
10
  class Y
13
- fastruby "
14
- def bar(x)
15
- i = 1000000
11
+ def bar(x)
12
+ i = 1000000
13
+
14
+ lvar_type(i,Fixnum)
16
15
 
17
- lvar_type(i,Fixnum)
18
-
19
- ret = 0
20
- while i > 0
21
- ret = x.foo(i,i)
22
- i = i - 1
23
- end
24
- return ret
16
+ ret = 0
17
+ while i > 0
18
+ ret = x.foo(i,i)
19
+ i = i - 1
25
20
  end
26
-
27
- "
28
- end
29
-
30
- class X2
31
- def foo(a,b)
32
- return a+b
21
+ return ret
33
22
  end
34
23
  end
35
24
 
36
- class Y2
37
- def bar(x)
38
- i = 1000000
39
- ret = 0
40
- while i > 0
41
- ret = x.foo(i,i)
42
- i = i - 1
43
- end
44
- return ret
45
- end
46
-
47
- end
48
-
49
25
 
50
26
  x = X.new
51
27
  y = Y.new
52
- y2 = Y2.new
53
- x2 = X2.new
54
-
55
- Y.build([Y,X],:bar)
56
- X.build([X,Fixnum,Fixnum],:foo)
57
28
 
58
29
  require 'benchmark'
59
30
 
60
31
  Benchmark::bm(20) do |b|
61
32
 
62
- b.report("fastruby") do
33
+ b.report("ruby") do
63
34
  y.bar(x)
64
35
  end
65
36
 
66
- b.report("ruby") do
67
- y2.bar(x2)
37
+ X.optimize(:foo)
38
+ Y.optimize(:bar)
39
+ X.build([X,Fixnum,Fixnum],:foo)
40
+ Y.build([Y,X],:bar)
41
+
42
+ b.report("fastruby") do
43
+ y.bar(x)
68
44
  end
69
45
  end
@@ -0,0 +1,47 @@
1
+ require "rubygems"
2
+ require "fastruby"
3
+
4
+ def lvar_type(*x); end
5
+
6
+ class X
7
+ def foo(a,b)
8
+ return a+b
9
+ end
10
+ end
11
+
12
+ class Y
13
+ def bar(x)
14
+ i = 1000000
15
+
16
+ lvar_type(i,Fixnum)
17
+
18
+ ret = 0
19
+ while i > 0
20
+ ret = x.foo(i,i)
21
+ i = i - 1
22
+ end
23
+ return ret
24
+ end
25
+ end
26
+
27
+
28
+ x = X.new
29
+ y = Y.new
30
+
31
+ require 'benchmark'
32
+
33
+ Benchmark::bm(20) do |b|
34
+
35
+ b.report("ruby") do
36
+ y.bar(x)
37
+ end
38
+
39
+ X.optimize(:foo)
40
+ Y.optimize(:bar)
41
+ X.build([X,Fixnum,Fixnum],:foo)
42
+ Y.build([Y,X],:bar)
43
+
44
+ b.report("fastruby") do
45
+ y.bar(x)
46
+ end
47
+ end
@@ -2,69 +2,43 @@ require "rubygems"
2
2
  require "fastruby"
3
3
 
4
4
  class X
5
- fastruby "
6
- def foo
7
- yield
8
- end
9
- "
5
+ def foo
6
+ yield
7
+ end
10
8
  end
11
9
 
12
10
  class Y
13
- fastruby "
14
- def bar(x)
15
- i = 1000000
11
+ def bar(x)
12
+ i = 1000000
16
13
 
17
- lvar_type(i,Fixnum)
14
+ lvar_type(i,Fixnum)
18
15
 
19
- ret = 0
20
- while i > 0
21
- x.foo do
22
- end
23
- i = i - 1
16
+ ret = 0
17
+ while i > 0
18
+ x.foo do
24
19
  end
25
- 0
20
+ i = i - 1
26
21
  end
27
-
28
- "
29
- end
30
-
31
- class X2
32
- def foo
33
- yield
22
+ 0
34
23
  end
35
24
  end
36
25
 
37
- class Y2
38
- def bar(x)
39
- i = 1000000
40
-
41
- ret = 0
42
- while i > 0
43
- x.foo do
44
- i = i - 1
45
- end
46
- end
47
- 0
48
- end
49
- end
50
-
51
-
52
26
  x = X.new
53
27
  y = Y.new
54
- y2 = Y2.new
55
- x2 = X2.new
56
-
57
- Y.build([Y,X],:bar)
58
28
 
59
29
  require 'benchmark'
60
30
 
61
31
  Benchmark::bm(20) do |b|
62
-
63
- b.report("fastruby") do
32
+ b.report("ruby") do
64
33
  y.bar(x)
65
34
  end
66
35
 
67
- b.report("ruby") do
68
- y2.bar(x2)
36
+ X.optimize(:foo)
37
+ Y.optimize(:bar)
38
+ X.build([X],:foo)
39
+ Y.build([Y,X],:bar)
40
+
41
+ b.report("fastruby") do
42
+ y.bar(x)
69
43
  end
70
44
  end
@@ -0,0 +1,46 @@
1
+ require "rubygems"
2
+ require "fastruby"
3
+
4
+ def lvar_type(*x); end
5
+
6
+ class X
7
+ def foo
8
+ yield
9
+ end
10
+ end
11
+
12
+ class Y
13
+ def bar(x)
14
+ i = 1000000
15
+
16
+ lvar_type(i,Fixnum)
17
+
18
+ ret = 0
19
+ while i > 0
20
+ x.foo do
21
+ end
22
+ i = i - 1
23
+ end
24
+ 0
25
+ end
26
+ end
27
+
28
+ x = X.new
29
+ y = Y.new
30
+
31
+ require 'benchmark'
32
+
33
+ Benchmark::bm(20) do |b|
34
+ b.report("ruby") do
35
+ y.bar(x)
36
+ end
37
+
38
+ X.optimize(:foo)
39
+ Y.optimize(:bar)
40
+ X.build([X],:foo)
41
+ Y.build([Y,X],:bar)
42
+
43
+ b.report("fastruby") do
44
+ y.bar(x)
45
+ end
46
+ end
@@ -2,69 +2,43 @@ require "rubygems"
2
2
  require "fastruby"
3
3
 
4
4
  class X
5
- fastruby "
6
- def foo
7
- yield(1,2,3)
8
- end
9
- "
5
+ def foo
6
+ yield(1,2,3)
7
+ end
10
8
  end
11
9
 
12
10
  class Y
13
- fastruby "
14
- def bar(x)
15
- i = 1000000
11
+ def bar(x)
12
+ i = 1000000
16
13
 
17
- lvar_type(i,Fixnum)
14
+ lvar_type(i,Fixnum)
18
15
 
19
- ret = 0
20
- while i > 0
21
- x.foo do |a,b,c|
22
- end
23
- i = i - 1
16
+ ret = 0
17
+ while i > 0
18
+ x.foo do |a,b,c|
24
19
  end
25
- 0
20
+ i = i - 1
26
21
  end
27
-
28
- "
29
- end
30
-
31
- class X2
32
- def foo
33
- yield
22
+ 0
34
23
  end
35
24
  end
36
25
 
37
- class Y2
38
- def bar(x)
39
- i = 1000000
40
-
41
- ret = 0
42
- while i > 0
43
- x.foo do
44
- i = i - 1
45
- end
46
- end
47
- 0
48
- end
49
- end
50
-
51
-
52
26
  x = X.new
53
27
  y = Y.new
54
- y2 = Y2.new
55
- x2 = X2.new
56
-
57
- Y.build([Y,X],:bar)
58
28
 
59
29
  require 'benchmark'
60
30
 
61
31
  Benchmark::bm(20) do |b|
62
-
63
- b.report("fastruby") do
32
+ b.report("ruby") do
64
33
  y.bar(x)
65
34
  end
66
35
 
67
- b.report("ruby") do
68
- y2.bar(x2)
36
+ X.optimize(:foo)
37
+ Y.optimize(:bar)
38
+ X.build([X],:foo)
39
+ Y.build([Y,X],:bar)
40
+
41
+ b.report("fastruby") do
42
+ y.bar(x)
69
43
  end
70
44
  end
@@ -0,0 +1,46 @@
1
+ require "rubygems"
2
+ require "fastruby"
3
+
4
+ def lvar_type(*x); end
5
+
6
+ class X
7
+ def foo
8
+ yield(1,2,3)
9
+ end
10
+ end
11
+
12
+ class Y
13
+ def bar(x)
14
+ i = 1000000
15
+
16
+ lvar_type(i,Fixnum)
17
+
18
+ ret = 0
19
+ while i > 0
20
+ x.foo do |a,b,c|
21
+ end
22
+ i = i - 1
23
+ end
24
+ 0
25
+ end
26
+ end
27
+
28
+ x = X.new
29
+ y = Y.new
30
+
31
+ require 'benchmark'
32
+
33
+ Benchmark::bm(20) do |b|
34
+ b.report("ruby") do
35
+ y.bar(x)
36
+ end
37
+
38
+ X.optimize(:foo)
39
+ Y.optimize(:bar)
40
+ X.build([X],:foo)
41
+ Y.build([Y,X],:bar)
42
+
43
+ b.report("fastruby") do
44
+ y.bar(x)
45
+ end
46
+ end
@@ -2,93 +2,58 @@ require "rubygems"
2
2
  require "fastruby"
3
3
 
4
4
  class Y
5
- fastruby "
6
- def bar
7
- i = 1000000
5
+ def bar
6
+ i = 1000000
8
7
 
9
- lvar_type(i,Fixnum)
8
+ lvar_type(i,Fixnum)
10
9
 
11
- ret = 0
12
- while i > 0
13
- $a = 9
14
- i = i - 1
15
- end
16
- 0
17
- end
18
-
19
- "
20
- end
21
-
22
- class Y2
23
- def bar
24
- i = 1000000
25
-
26
- ret = 0
27
- while i > 0
28
- $a = 9
29
- i = i - 1
30
- end
31
- 0
10
+ ret = 0
11
+ while i > 0
12
+ $a = 9
13
+ i = i - 1
32
14
  end
15
+ 0
16
+ end
33
17
  end
34
18
 
35
-
36
19
  class Y_
37
- fastruby "
38
- def bar
39
- i = 1000000
20
+ def bar
21
+ i = 1000000
40
22
 
41
- lvar_type(i,Fixnum)
23
+ lvar_type(i,Fixnum)
42
24
 
43
- ret = 0
44
- while i > 0
45
- i = i - 1
46
- end
47
- 0
48
- end
49
-
50
- "
51
- end
52
-
53
- class Y2_
54
- def bar
55
- i = 1000000
56
-
57
- ret = 0
58
- while i > 0
59
- i = i - 1
60
- end
61
- 0
25
+ ret = 0
26
+ while i > 0
27
+ i = i - 1
62
28
  end
29
+ 0
30
+ end
63
31
  end
64
32
 
65
-
66
33
  y = Y.new
67
- y2 = Y2.new
68
34
  y_ = Y_.new
69
- y2_ = Y2_.new
70
-
71
- Y.build([Y],:bar)
72
- Y_.build([Y_],:bar)
73
-
74
35
  require 'benchmark'
75
36
 
76
37
  Benchmark::bm(20) do |b|
77
38
 
78
- b.report("fastruby") do
39
+ b.report("ruby") do
79
40
  y.bar
80
41
  end
81
42
 
82
- b.report("ruby") do
83
- y2.bar
84
- end
85
-
86
- b.report("lfastruby") do
43
+ b.report("lruby") do
87
44
  y_.bar
88
45
  end
89
46
 
90
- b.report("lruby") do
91
- y2_.bar
47
+ Y.optimize(:bar)
48
+ Y_.optimize(:bar)
49
+ Y.build([Y],:bar)
50
+ Y_.build([Y_],:bar)
51
+
52
+ b.report("fastruby") do
53
+ y.bar
54
+ end
55
+
56
+ b.report("lfastruby") do
57
+ y_.bar
92
58
  end
93
-
94
59
  end
@@ -0,0 +1,61 @@
1
+ require "rubygems"
2
+ require "fastruby"
3
+
4
+ def lvar_type(*x); end
5
+
6
+ class Y
7
+ def bar
8
+ i = 1000000
9
+
10
+ lvar_type(i,Fixnum)
11
+
12
+ ret = 0
13
+ while i > 0
14
+ $a = 9
15
+ i = i - 1
16
+ end
17
+ 0
18
+ end
19
+ end
20
+
21
+ class Y_
22
+ def bar
23
+ i = 1000000
24
+
25
+ lvar_type(i,Fixnum)
26
+
27
+ ret = 0
28
+ while i > 0
29
+ i = i - 1
30
+ end
31
+ 0
32
+ end
33
+ end
34
+
35
+ y = Y.new
36
+ y_ = Y_.new
37
+ require 'benchmark'
38
+
39
+ Benchmark::bm(20) do |b|
40
+
41
+ b.report("ruby") do
42
+ y.bar
43
+ end
44
+
45
+ b.report("lruby") do
46
+ y_.bar
47
+ end
48
+
49
+ Y.optimize(:bar)
50
+ Y_.optimize(:bar)
51
+ Y.build([Y],:bar)
52
+ Y_.build([Y_],:bar)
53
+
54
+ b.report("fastruby") do
55
+ y.bar
56
+ end
57
+
58
+ b.report("lfastruby") do
59
+ y_.bar
60
+ end
61
+ end