flows 0.2.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/{build.yml → test.yml} +5 -10
  3. data/.gitignore +9 -1
  4. data/.mdlrc +1 -1
  5. data/.reek.yml +54 -0
  6. data/.rubocop.yml +26 -7
  7. data/.rubocop_todo.yml +27 -0
  8. data/.ruby-version +1 -1
  9. data/.yardopts +1 -0
  10. data/CHANGELOG.md +81 -0
  11. data/Gemfile +0 -6
  12. data/README.md +167 -363
  13. data/Rakefile +35 -1
  14. data/bin/.rubocop.yml +5 -0
  15. data/bin/all_the_errors +55 -0
  16. data/bin/benchmark +73 -105
  17. data/bin/benchmark_cli/compare.rb +118 -0
  18. data/bin/benchmark_cli/compare/a_plus_b.rb +22 -0
  19. data/bin/benchmark_cli/compare/base.rb +45 -0
  20. data/bin/benchmark_cli/compare/command.rb +47 -0
  21. data/bin/benchmark_cli/compare/ten_steps.rb +22 -0
  22. data/bin/benchmark_cli/examples.rb +23 -0
  23. data/bin/benchmark_cli/examples/.rubocop.yml +22 -0
  24. data/bin/benchmark_cli/examples/a_plus_b/dry_do.rb +23 -0
  25. data/bin/benchmark_cli/examples/a_plus_b/dry_transaction.rb +17 -0
  26. data/bin/benchmark_cli/examples/a_plus_b/flows_do.rb +22 -0
  27. data/bin/benchmark_cli/examples/a_plus_b/flows_railway.rb +13 -0
  28. data/bin/benchmark_cli/examples/a_plus_b/flows_scp.rb +13 -0
  29. data/bin/benchmark_cli/examples/a_plus_b/flows_scp_mut.rb +13 -0
  30. data/bin/benchmark_cli/examples/a_plus_b/flows_scp_oc.rb +21 -0
  31. data/bin/benchmark_cli/examples/a_plus_b/trailblazer.rb +15 -0
  32. data/bin/benchmark_cli/examples/ten_steps/dry_do.rb +70 -0
  33. data/bin/benchmark_cli/examples/ten_steps/dry_transaction.rb +64 -0
  34. data/bin/benchmark_cli/examples/ten_steps/flows_do.rb +69 -0
  35. data/bin/benchmark_cli/examples/ten_steps/flows_railway.rb +58 -0
  36. data/bin/benchmark_cli/examples/ten_steps/flows_scp.rb +58 -0
  37. data/bin/benchmark_cli/examples/ten_steps/flows_scp_mut.rb +58 -0
  38. data/bin/benchmark_cli/examples/ten_steps/flows_scp_oc.rb +66 -0
  39. data/bin/benchmark_cli/examples/ten_steps/trailblazer.rb +60 -0
  40. data/bin/benchmark_cli/helpers.rb +12 -0
  41. data/bin/benchmark_cli/ruby.rb +15 -0
  42. data/bin/benchmark_cli/ruby/command.rb +38 -0
  43. data/bin/benchmark_cli/ruby/method_exec.rb +71 -0
  44. data/bin/benchmark_cli/ruby/self_class.rb +69 -0
  45. data/bin/benchmark_cli/ruby/structs.rb +90 -0
  46. data/bin/console +1 -0
  47. data/bin/docserver +7 -0
  48. data/bin/errors +138 -0
  49. data/bin/errors_cli/contract_error_demo.rb +49 -0
  50. data/bin/errors_cli/di_error_demo.rb +38 -0
  51. data/bin/errors_cli/flow_error_demo.rb +22 -0
  52. data/bin/errors_cli/flows_router_error_demo.rb +15 -0
  53. data/bin/errors_cli/interface_error_demo.rb +17 -0
  54. data/bin/errors_cli/oc_error_demo.rb +40 -0
  55. data/bin/errors_cli/railway_error_demo.rb +10 -0
  56. data/bin/errors_cli/result_error_demo.rb +13 -0
  57. data/bin/errors_cli/scp_error_demo.rb +17 -0
  58. data/docs/README.md +3 -187
  59. data/docs/_sidebar.md +0 -24
  60. data/docs/index.html +1 -1
  61. data/flows.gemspec +27 -2
  62. data/forspell.dict +9 -0
  63. data/lefthook.yml +9 -0
  64. data/lib/flows.rb +11 -5
  65. data/lib/flows/contract.rb +402 -0
  66. data/lib/flows/contract/array.rb +55 -0
  67. data/lib/flows/contract/case_eq.rb +43 -0
  68. data/lib/flows/contract/compose.rb +77 -0
  69. data/lib/flows/contract/either.rb +53 -0
  70. data/lib/flows/contract/error.rb +24 -0
  71. data/lib/flows/contract/hash.rb +75 -0
  72. data/lib/flows/contract/hash_of.rb +70 -0
  73. data/lib/flows/contract/helpers.rb +22 -0
  74. data/lib/flows/contract/predicate.rb +34 -0
  75. data/lib/flows/contract/transformer.rb +50 -0
  76. data/lib/flows/contract/tuple.rb +70 -0
  77. data/lib/flows/flow.rb +96 -7
  78. data/lib/flows/flow/errors.rb +29 -0
  79. data/lib/flows/flow/node.rb +132 -0
  80. data/lib/flows/flow/router.rb +29 -0
  81. data/lib/flows/flow/router/custom.rb +59 -0
  82. data/lib/flows/flow/router/errors.rb +11 -0
  83. data/lib/flows/flow/router/simple.rb +25 -0
  84. data/lib/flows/plugin.rb +15 -0
  85. data/lib/flows/plugin/dependency_injector.rb +170 -0
  86. data/lib/flows/plugin/dependency_injector/dependency.rb +24 -0
  87. data/lib/flows/plugin/dependency_injector/dependency_definition.rb +16 -0
  88. data/lib/flows/plugin/dependency_injector/dependency_list.rb +55 -0
  89. data/lib/flows/plugin/dependency_injector/errors.rb +58 -0
  90. data/lib/flows/plugin/implicit_init.rb +45 -0
  91. data/lib/flows/plugin/interface.rb +84 -0
  92. data/lib/flows/plugin/output_contract.rb +85 -0
  93. data/lib/flows/plugin/output_contract/dsl.rb +48 -0
  94. data/lib/flows/plugin/output_contract/errors.rb +74 -0
  95. data/lib/flows/plugin/output_contract/wrapper.rb +55 -0
  96. data/lib/flows/plugin/profiler.rb +114 -0
  97. data/lib/flows/plugin/profiler/injector.rb +35 -0
  98. data/lib/flows/plugin/profiler/report.rb +48 -0
  99. data/lib/flows/plugin/profiler/report/events.rb +43 -0
  100. data/lib/flows/plugin/profiler/report/flat.rb +41 -0
  101. data/lib/flows/plugin/profiler/report/flat/method_report.rb +80 -0
  102. data/lib/flows/plugin/profiler/report/raw.rb +15 -0
  103. data/lib/flows/plugin/profiler/report/tree.rb +98 -0
  104. data/lib/flows/plugin/profiler/report/tree/calculated_node.rb +116 -0
  105. data/lib/flows/plugin/profiler/report/tree/node.rb +34 -0
  106. data/lib/flows/plugin/profiler/wrapper.rb +53 -0
  107. data/lib/flows/railway.rb +140 -34
  108. data/lib/flows/railway/dsl.rb +8 -18
  109. data/lib/flows/railway/errors.rb +8 -12
  110. data/lib/flows/railway/step.rb +24 -0
  111. data/lib/flows/railway/step_list.rb +38 -0
  112. data/lib/flows/result.rb +188 -2
  113. data/lib/flows/result/do.rb +158 -16
  114. data/lib/flows/result/err.rb +12 -6
  115. data/lib/flows/result/errors.rb +29 -17
  116. data/lib/flows/result/helpers.rb +25 -3
  117. data/lib/flows/result/ok.rb +12 -6
  118. data/lib/flows/shared_context_pipeline.rb +342 -0
  119. data/lib/flows/shared_context_pipeline/dsl.rb +12 -0
  120. data/lib/flows/shared_context_pipeline/dsl/callbacks.rb +35 -0
  121. data/lib/flows/shared_context_pipeline/dsl/tracks.rb +52 -0
  122. data/lib/flows/shared_context_pipeline/errors.rb +17 -0
  123. data/lib/flows/shared_context_pipeline/mutation_step.rb +30 -0
  124. data/lib/flows/shared_context_pipeline/router_definition.rb +21 -0
  125. data/lib/flows/shared_context_pipeline/step.rb +55 -0
  126. data/lib/flows/shared_context_pipeline/track.rb +54 -0
  127. data/lib/flows/shared_context_pipeline/track_list.rb +51 -0
  128. data/lib/flows/shared_context_pipeline/wrap.rb +73 -0
  129. data/lib/flows/util.rb +17 -0
  130. data/lib/flows/util/inheritable_singleton_vars.rb +86 -0
  131. data/lib/flows/util/inheritable_singleton_vars/dup_strategy.rb +100 -0
  132. data/lib/flows/util/inheritable_singleton_vars/isolation_strategy.rb +91 -0
  133. data/lib/flows/util/prepend_to_class.rb +191 -0
  134. data/lib/flows/version.rb +1 -1
  135. metadata +253 -38
  136. data/Gemfile.lock +0 -174
  137. data/bin/demo +0 -66
  138. data/bin/examples.rb +0 -195
  139. data/bin/profile_10steps +0 -106
  140. data/bin/ruby_benchmarks +0 -26
  141. data/docs/CNAME +0 -1
  142. data/docs/contributing/benchmarks_profiling.md +0 -3
  143. data/docs/contributing/local_development.md +0 -3
  144. data/docs/flow/direct_usage.md +0 -3
  145. data/docs/flow/general_idea.md +0 -3
  146. data/docs/operation/basic_usage.md +0 -1
  147. data/docs/operation/inject_steps.md +0 -3
  148. data/docs/operation/lambda_steps.md +0 -3
  149. data/docs/operation/result_shapes.md +0 -3
  150. data/docs/operation/routing_tracks.md +0 -3
  151. data/docs/operation/wrapping_steps.md +0 -3
  152. data/docs/overview/performance.md +0 -336
  153. data/docs/railway/basic_usage.md +0 -232
  154. data/docs/result_objects/basic_usage.md +0 -196
  155. data/docs/result_objects/do_notation.md +0 -139
  156. data/lib/flows/node.rb +0 -27
  157. data/lib/flows/operation.rb +0 -52
  158. data/lib/flows/operation/builder.rb +0 -130
  159. data/lib/flows/operation/builder/build_router.rb +0 -37
  160. data/lib/flows/operation/dsl.rb +0 -93
  161. data/lib/flows/operation/errors.rb +0 -75
  162. data/lib/flows/operation/executor.rb +0 -78
  163. data/lib/flows/railway/builder.rb +0 -68
  164. data/lib/flows/railway/executor.rb +0 -23
  165. data/lib/flows/result_router.rb +0 -14
  166. data/lib/flows/router.rb +0 -22
@@ -1,174 +0,0 @@
1
- GIT
2
- remote: git://github.com/ffloyd/markdownlint.git
3
- revision: 801cb12f645d894e0d262bb4908d8086b6dd23bc
4
- branch: update-kramdown-dep
5
- specs:
6
- mdl (0.5.0)
7
- kramdown (~> 2.0)
8
- kramdown-parser-gfm (~> 1.0)
9
- mixlib-cli (~> 1.7, >= 1.7.0)
10
- mixlib-config (~> 2.2, >= 2.2.1)
11
-
12
- PATH
13
- remote: .
14
- specs:
15
- flows (0.2.0)
16
-
17
- GEM
18
- remote: https://rubygems.org/
19
- specs:
20
- ast (2.4.0)
21
- backports (3.15.0)
22
- benchmark-ips (2.7.2)
23
- codecov (0.1.14)
24
- json
25
- simplecov
26
- url
27
- coderay (1.1.2)
28
- concurrent-ruby (1.1.5)
29
- crass (1.0.4)
30
- diff-lcs (1.3)
31
- docile (1.3.2)
32
- dry-configurable (0.8.3)
33
- concurrent-ruby (~> 1.0)
34
- dry-core (~> 0.4, >= 0.4.7)
35
- dry-container (0.7.2)
36
- concurrent-ruby (~> 1.0)
37
- dry-configurable (~> 0.1, >= 0.1.3)
38
- dry-core (0.4.9)
39
- concurrent-ruby (~> 1.0)
40
- dry-equalizer (0.2.2)
41
- dry-events (0.2.0)
42
- concurrent-ruby (~> 1.0)
43
- dry-core (~> 0.4)
44
- dry-equalizer (~> 0.2)
45
- dry-matcher (0.8.2)
46
- dry-core (>= 0.4.8)
47
- dry-monads (1.3.1)
48
- concurrent-ruby (~> 1.0)
49
- dry-core (~> 0.4, >= 0.4.4)
50
- dry-equalizer
51
- dry-transaction (0.13.0)
52
- dry-container (>= 0.2.8)
53
- dry-events (>= 0.1.0)
54
- dry-matcher (>= 0.7.0)
55
- dry-monads (>= 0.4.0)
56
- equatable (0.6.1)
57
- ffi (1.11.1)
58
- ffi-hunspell (0.4.0)
59
- ffi (~> 1.0)
60
- forspell (0.0.8)
61
- backports (~> 3.0)
62
- ffi-hunspell
63
- highline
64
- kramdown (~> 2.0)
65
- kramdown-parser-gfm (~> 1.0)
66
- parser
67
- pastel
68
- ruby-progressbar
69
- sanitize (~> 5.0)
70
- slop (~> 4.6)
71
- yard
72
- highline (2.0.2)
73
- jaro_winkler (1.5.3)
74
- json (2.2.0)
75
- kramdown (2.1.0)
76
- kramdown-parser-gfm (1.1.0)
77
- kramdown (~> 2.0)
78
- method_source (0.9.2)
79
- mini_portile2 (2.4.0)
80
- mixlib-cli (1.7.0)
81
- mixlib-config (2.2.18)
82
- tomlrb
83
- nokogiri (1.10.4)
84
- mini_portile2 (~> 2.4.0)
85
- nokogumbo (2.0.1)
86
- nokogiri (~> 1.8, >= 1.8.4)
87
- parallel (1.17.0)
88
- parser (2.6.4.1)
89
- ast (~> 2.4.0)
90
- pastel (0.7.3)
91
- equatable (~> 0.6)
92
- tty-color (~> 0.5)
93
- pry (0.12.2)
94
- coderay (~> 1.1.0)
95
- method_source (~> 0.9.0)
96
- rainbow (3.0.0)
97
- rake (10.5.0)
98
- rspec (3.8.0)
99
- rspec-core (~> 3.8.0)
100
- rspec-expectations (~> 3.8.0)
101
- rspec-mocks (~> 3.8.0)
102
- rspec-core (3.8.2)
103
- rspec-support (~> 3.8.0)
104
- rspec-expectations (3.8.4)
105
- diff-lcs (>= 1.2.0, < 2.0)
106
- rspec-support (~> 3.8.0)
107
- rspec-mocks (3.8.1)
108
- diff-lcs (>= 1.2.0, < 2.0)
109
- rspec-support (~> 3.8.0)
110
- rspec-support (3.8.2)
111
- rubocop (0.74.0)
112
- jaro_winkler (~> 1.5.1)
113
- parallel (~> 1.10)
114
- parser (>= 2.6)
115
- rainbow (>= 2.2.2, < 4.0)
116
- ruby-progressbar (~> 1.7)
117
- unicode-display_width (>= 1.4.0, < 1.7)
118
- rubocop-md (0.3.0)
119
- rubocop (~> 0.60)
120
- rubocop-performance (1.4.1)
121
- rubocop (>= 0.71.0)
122
- rubocop-rspec (1.35.0)
123
- rubocop (>= 0.60.0)
124
- ruby-prof (1.0.0)
125
- ruby-progressbar (1.10.1)
126
- sanitize (5.1.0)
127
- crass (~> 1.0.2)
128
- nokogiri (>= 1.8.0)
129
- nokogumbo (~> 2.0)
130
- simplecov (0.17.1)
131
- docile (~> 1.1)
132
- json (>= 1.8, < 3)
133
- simplecov-html (~> 0.10.0)
134
- simplecov-html (0.10.2)
135
- slop (4.7.0)
136
- stackprof (0.2.12)
137
- tomlrb (1.2.8)
138
- trailblazer-activity (0.9.0)
139
- trailblazer-context (>= 0.1.4)
140
- trailblazer-activity-dsl-linear (0.2.0)
141
- trailblazer-activity (>= 0.9.0, < 1.0.0)
142
- trailblazer-context (0.1.4)
143
- trailblazer-operation (0.5.2)
144
- trailblazer-activity-dsl-linear (>= 0.1.6, < 1.0.0)
145
- tty-color (0.5.0)
146
- unicode-display_width (1.6.0)
147
- url (0.3.2)
148
- yard (0.9.20)
149
-
150
- PLATFORMS
151
- ruby
152
-
153
- DEPENDENCIES
154
- benchmark-ips
155
- bundler (~> 2.0)
156
- codecov
157
- dry-transaction
158
- flows!
159
- forspell (~> 0.0.8)
160
- mdl!
161
- pry
162
- rake (~> 10.0)
163
- rspec (~> 3.0)
164
- rubocop
165
- rubocop-md
166
- rubocop-performance
167
- rubocop-rspec
168
- ruby-prof
169
- simplecov
170
- stackprof
171
- trailblazer-operation
172
-
173
- BUNDLED WITH
174
- 2.0.1
data/bin/demo DELETED
@@ -1,66 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'flows'
5
-
6
- # Helper for demonstrations
7
- module Demo
8
- def self.run(name)
9
- puts '-' * 60
10
- puts name
11
- puts '-' * 60
12
- puts
13
-
14
- begin
15
- yield
16
- rescue StandardError => e
17
- puts "Exception raised:\n\n#{e.full_message}"
18
- end
19
- puts "\n" + '-' * 60 + "\n" * 2
20
- end
21
- end
22
-
23
- # Simple division
24
- class DivisionOperation
25
- include Flows::Operation
26
-
27
- step :check_for_zero
28
- step :divide
29
-
30
- ok_shape :result
31
- err_shape :error
32
-
33
- def check_for_zero(denominator:, **)
34
- if denominator.zero?
35
- err(error: 'Denominator cannot be zero')
36
- else
37
- ok
38
- end
39
- end
40
-
41
- def divide(numerator:, denominator:, **)
42
- ok(result: numerator / denominator)
43
- end
44
- end
45
-
46
- # Division in nested operation - we do division
47
- class NestedDivisionOperation
48
- include Flows::Operation
49
-
50
- step :do_division
51
-
52
- ok_shape :result
53
- err_shape :error
54
-
55
- def do_division(**params)
56
- DivisionOperation.new.call(**params)
57
- end
58
- end
59
-
60
- Demo.run 'Unwrap Error verbosity' do
61
- DivisionOperation.new.call(numerator: 1, denominator: 0).unwrap[:result]
62
- end
63
-
64
- Demo.run 'Unwrap Error verbosity when error happened in nested operation' do
65
- NestedDivisionOperation.new.call(numerator: 1, denominator: 0).unwrap[:result]
66
- end
@@ -1,195 +0,0 @@
1
- # rubocop:disable all
2
- require 'flows'
3
- require 'dry/transaction'
4
- require 'trailblazer/operation'
5
-
6
- #
7
- # Task: a + b = ?
8
- #
9
-
10
- class FlowsSummator
11
- include Flows::Operation
12
-
13
- step :sum
14
-
15
- ok_shape :sum
16
-
17
- def sum(a:, b:, **)
18
- ok(sum: a + b)
19
- end
20
- end
21
-
22
- class FlowsRailwaySummator
23
- include Flows::Railway
24
-
25
- step :sum
26
-
27
- def sum(a:, b:)
28
- ok(sum: a + b)
29
- end
30
- end
31
-
32
- class POROSummator
33
- def self.call(a:, b:)
34
- a + b
35
- end
36
- end
37
-
38
- class DrySummator
39
- include Dry::Transaction
40
-
41
- step :sum
42
-
43
- private
44
-
45
- def sum(a:, b:)
46
- Success(a + b)
47
- end
48
- end
49
-
50
- class TBSummator < Trailblazer::Operation
51
- step :sum
52
-
53
- def sum(opts, a:, b:, **)
54
- opts[:sum] = a + b
55
- end
56
- end
57
-
58
- #
59
- # Task: 10 steps which returns simple value
60
- #
61
-
62
- class FlowsTenSteps
63
- include Flows::Operation
64
-
65
- step :s1
66
- step :s2
67
- step :s3
68
- step :s4
69
- step :s5
70
- step :s6
71
- step :s7
72
- step :s8
73
- step :s9
74
- step :s10
75
-
76
- ok_shape :data
77
-
78
- def s1(**); ok(s1: true); end
79
- def s2(**); ok(s2: true); end
80
- def s3(**); ok(s3: true); end
81
- def s4(**); ok(s4: true); end
82
- def s5(**); ok(s5: true); end
83
- def s5(**); ok(s5: true); end
84
- def s6(**); ok(s6: true); end
85
- def s7(**); ok(s7: true); end
86
- def s8(**); ok(s8: true); end
87
- def s9(**); ok(s9: true); end
88
- def s10(**); ok(data: :ok); end
89
- end
90
-
91
- class FlowsRailwayTenSteps
92
- include Flows::Railway
93
-
94
- step :s1
95
- step :s2
96
- step :s3
97
- step :s4
98
- step :s5
99
- step :s6
100
- step :s7
101
- step :s8
102
- step :s9
103
- step :s10
104
-
105
- def s1(**); ok(s1: true); end
106
- def s2(s1:); ok(s2: s1); end
107
- def s3(s2:); ok(s3: s2); end
108
- def s4(s3:); ok(s4: s3); end
109
- def s5(s4:); ok(s5: s4); end
110
- def s6(s5:); ok(s6: s5); end
111
- def s7(s6:); ok(s7: s6); end
112
- def s8(s7:); ok(s8: s7); end
113
- def s9(s8:); ok(s9: s8); end
114
- def s10(s9:); ok(data: :ok); end
115
- end
116
-
117
- class POROTenSteps
118
- class << self
119
- def call()
120
- s1
121
- s2
122
- s3
123
- s4
124
- s5
125
- s6
126
- s7
127
- s8
128
- s9
129
- s10
130
- end
131
-
132
- def s1; true; end
133
- def s2; true; end
134
- def s3; true; end
135
- def s4; true; end
136
- def s5; true; end
137
- def s6; true; end
138
- def s7; true; end
139
- def s8; true; end
140
- def s9; true; end
141
- def s10; true; end
142
- end
143
- end
144
-
145
- class DryTenSteps
146
- include Dry::Transaction
147
-
148
- step :s1
149
- step :s2
150
- step :s3
151
- step :s4
152
- step :s5
153
- step :s6
154
- step :s7
155
- step :s8
156
- step :s9
157
- step :s10
158
-
159
- private
160
-
161
- def s1; Success(true); end
162
- def s2; Success(true); end
163
- def s3; Success(true); end
164
- def s4; Success(true); end
165
- def s5; Success(true); end
166
- def s6; Success(true); end
167
- def s7; Success(true); end
168
- def s8; Success(true); end
169
- def s9; Success(true); end
170
- def s10; Success(true); end
171
- end
172
-
173
- class TBTenSteps < Trailblazer::Operation
174
- step :s1
175
- step :s2
176
- step :s3
177
- step :s4
178
- step :s5
179
- step :s6
180
- step :s7
181
- step :s8
182
- step :s9
183
- step :s10
184
-
185
- def s1(opts, **); opts[:s1] = true; end
186
- def s2(opts, **); opts[:s2] = true; end
187
- def s3(opts, **); opts[:s3] = true; end
188
- def s4(opts, **); opts[:s4] = true; end
189
- def s5(opts, **); opts[:s5] = true; end
190
- def s6(opts, **); opts[:s6] = true; end
191
- def s7(opts, **); opts[:s7] = true; end
192
- def s8(opts, **); opts[:s8] = true; end
193
- def s9(opts, **); opts[:s9] = true; end
194
- def s10(opts, **); opts[:s10] = true; end
195
- end
@@ -1,106 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # rubocop:disable all
3
-
4
- require 'bundler/setup'
5
- require 'json'
6
- require 'ruby-prof'
7
- require 'stackprof'
8
-
9
- require_relative './examples'
10
-
11
- flows_ten_steps = FlowsTenSteps.new
12
- flows_railway_ten_steps = FlowsRailwayTenSteps.new
13
-
14
- build_output_name = '10steps_build_10k_times'
15
- exec_output_name = '10steps_execution_10k_times'
16
-
17
- #
18
- # RubyProf
19
- #
20
- RubyProf.measure_mode = RubyProf::WALL_TIME
21
-
22
-
23
- puts 'Build with RubyProf...'
24
-
25
- result = RubyProf.profile do
26
- 10_000.times do
27
- FlowsTenSteps.new
28
- end
29
- end
30
- printer = RubyProf::MultiPrinter.new(result)
31
- printer.print(path: 'profile', profile: "#{build_output_name}_operaion")
32
-
33
- result = RubyProf.profile do
34
- 10_000.times do
35
- FlowsRailwayTenSteps.new
36
- end
37
- end
38
- printer = RubyProf::MultiPrinter.new(result)
39
- printer.print(path: 'profile', profile: "#{build_output_name}_railway")
40
-
41
-
42
- puts 'Execution with RubyProf...'
43
-
44
- result = RubyProf.profile do
45
- 10_000.times {
46
- flows_ten_steps.call
47
- }
48
- end
49
- printer = RubyProf::MultiPrinter.new(result)
50
- printer.print(path: 'profile', profile: "#{exec_output_name}_operation")
51
-
52
- result = RubyProf.profile do
53
- 10_000.times {
54
- flows_railway_ten_steps.call
55
- }
56
- end
57
- printer = RubyProf::MultiPrinter.new(result)
58
- printer.print(path: 'profile', profile: "#{exec_output_name}_railway")
59
-
60
-
61
- #
62
- # StackProf
63
- #
64
-
65
- puts 'Build with StackProf...'
66
-
67
- result = StackProf.run(mode: :wall, raw: true) do
68
- 10_000.times do
69
- FlowsTenSteps.new
70
- end
71
- end
72
- File.write("profile/#{build_output_name}_operation.json", JSON.generate(result))
73
-
74
- result = StackProf.run(mode: :wall, raw: true) do
75
- 10_000.times do
76
- FlowsRailwayTenSteps.new
77
- end
78
- end
79
- File.write("profile/#{build_output_name}_railway.json", JSON.generate(result))
80
-
81
-
82
- puts 'Execution with StackProf...'
83
-
84
- result = StackProf.run(mode: :wall, raw: true) do
85
- 10_000.times do
86
- flows_ten_steps.call
87
- end
88
- end
89
- File.write("profile/#{exec_output_name}_operation.json", JSON.generate(result))
90
-
91
- result = StackProf.run(mode: :wall, raw: true) do
92
- 10_000.times do
93
- flows_railway_ten_steps.call
94
- end
95
- end
96
- File.write("profile/#{exec_output_name}_railway.json", JSON.generate(result))
97
-
98
-
99
- puts
100
- puts 'Install speedscope:'
101
- puts ' npm i -g speedscope'
102
- puts
103
- puts "speedscope profile/#{build_output_name}_operation.json"
104
- puts "speedscope profile/#{build_output_name}_railway.json"
105
- puts "speedscope profile/#{exec_output_name}_operation.json"
106
- puts "speedscope profile/#{exec_output_name}_railway.json"