laser 0.7.0.pre1

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 (319) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +14 -0
  4. data/LICENSE +661 -0
  5. data/README.md +158 -0
  6. data/Rakefile +104 -0
  7. data/VERSION +1 -0
  8. data/bin/laser +7 -0
  9. data/design_docs/goals.md +57 -0
  10. data/design_docs/object_regex.md +426 -0
  11. data/design_docs/type_annotations.md +80 -0
  12. data/ext/laser/BasicBlock.cpp +572 -0
  13. data/ext/laser/BasicBlock.h +118 -0
  14. data/ext/laser/extconf.rb +3 -0
  15. data/features/laser.feature +25 -0
  16. data/features/step_definitions/laser_steps.rb +39 -0
  17. data/features/support/env.rb +14 -0
  18. data/features/support/testdata/1_input +1 -0
  19. data/features/support/testdata/1_output +1 -0
  20. data/features/support/testdata/2_input +4 -0
  21. data/features/support/testdata/2_output +4 -0
  22. data/features/support/testdata/3_input +8 -0
  23. data/features/support/testdata/3_output +11 -0
  24. data/features/support/testdata/4_input +5 -0
  25. data/features/support/testdata/4_output +5 -0
  26. data/features/support/testdata/5_input +13 -0
  27. data/laser.gemspec +382 -0
  28. data/lib/laser.rb +98 -0
  29. data/lib/laser/analysis/annotations.rb +95 -0
  30. data/lib/laser/analysis/annotations/annotation_config.yaml +3 -0
  31. data/lib/laser/analysis/annotations/comment_attachment_annotation.rb +66 -0
  32. data/lib/laser/analysis/annotations/node_pointers_annotation.rb +36 -0
  33. data/lib/laser/analysis/annotations/runtime_annotation.rb +55 -0
  34. data/lib/laser/analysis/argument_expansion.rb +132 -0
  35. data/lib/laser/analysis/arity.rb +34 -0
  36. data/lib/laser/analysis/bindings.rb +144 -0
  37. data/lib/laser/analysis/bootstrap/bootstrap.rb +298 -0
  38. data/lib/laser/analysis/bootstrap/laser_class.rb +106 -0
  39. data/lib/laser/analysis/bootstrap/laser_method.rb +255 -0
  40. data/lib/laser/analysis/bootstrap/laser_module.rb +403 -0
  41. data/lib/laser/analysis/bootstrap/laser_module_copy.rb +74 -0
  42. data/lib/laser/analysis/bootstrap/laser_object.rb +69 -0
  43. data/lib/laser/analysis/bootstrap/laser_proc.rb +150 -0
  44. data/lib/laser/analysis/bootstrap/laser_singleton_class.rb +44 -0
  45. data/lib/laser/analysis/comments.rb +35 -0
  46. data/lib/laser/analysis/control_flow.rb +28 -0
  47. data/lib/laser/analysis/control_flow/alias_analysis.rb +31 -0
  48. data/lib/laser/analysis/control_flow/basic_block.rb +105 -0
  49. data/lib/laser/analysis/control_flow/cfg_builder.rb +2505 -0
  50. data/lib/laser/analysis/control_flow/cfg_instruction.rb +190 -0
  51. data/lib/laser/analysis/control_flow/constant_propagation.rb +742 -0
  52. data/lib/laser/analysis/control_flow/control_flow_graph.rb +370 -0
  53. data/lib/laser/analysis/control_flow/lifetime_analysis.rb +91 -0
  54. data/lib/laser/analysis/control_flow/method_call_search.rb +26 -0
  55. data/lib/laser/analysis/control_flow/raise_properties.rb +25 -0
  56. data/lib/laser/analysis/control_flow/simulation.rb +385 -0
  57. data/lib/laser/analysis/control_flow/static_single_assignment.rb +185 -0
  58. data/lib/laser/analysis/control_flow/unreachability_analysis.rb +57 -0
  59. data/lib/laser/analysis/control_flow/unused_variables.rb +91 -0
  60. data/lib/laser/analysis/control_flow/yield_properties.rb +103 -0
  61. data/lib/laser/analysis/errors.rb +131 -0
  62. data/lib/laser/analysis/laser_utils.rb +18 -0
  63. data/lib/laser/analysis/lexical_analysis.rb +172 -0
  64. data/lib/laser/analysis/method_call.rb +68 -0
  65. data/lib/laser/analysis/protocol_registry.rb +30 -0
  66. data/lib/laser/analysis/scope.rb +118 -0
  67. data/lib/laser/analysis/sexp.rb +159 -0
  68. data/lib/laser/analysis/sexp_analysis.rb +40 -0
  69. data/lib/laser/analysis/sexp_extensions/constant_extraction.rb +115 -0
  70. data/lib/laser/analysis/sexp_extensions/source_location.rb +164 -0
  71. data/lib/laser/analysis/sexp_extensions/type_inference.rb +47 -0
  72. data/lib/laser/analysis/signature.rb +76 -0
  73. data/lib/laser/analysis/special_methods/send.rb +67 -0
  74. data/lib/laser/analysis/unused_methods.rb +21 -0
  75. data/lib/laser/analysis/visitor.rb +141 -0
  76. data/lib/laser/annotation_parser/annotations.treetop +126 -0
  77. data/lib/laser/annotation_parser/annotations_parser.rb +748 -0
  78. data/lib/laser/annotation_parser/class_annotations.treetop +82 -0
  79. data/lib/laser/annotation_parser/class_annotations_parser.rb +654 -0
  80. data/lib/laser/annotation_parser/overload.treetop +24 -0
  81. data/lib/laser/annotation_parser/overload_parser.rb +167 -0
  82. data/lib/laser/annotation_parser/parsers.rb +6 -0
  83. data/lib/laser/annotation_parser/structural.treetop +37 -0
  84. data/lib/laser/annotation_parser/structural_parser.rb +406 -0
  85. data/lib/laser/annotation_parser/useful_parsers.treetop +47 -0
  86. data/lib/laser/annotation_parser/useful_parsers_parser.rb +674 -0
  87. data/lib/laser/rake/task.rb +46 -0
  88. data/lib/laser/runner.rb +189 -0
  89. data/lib/laser/scanner.rb +169 -0
  90. data/lib/laser/standard_library/_thread.rb +110 -0
  91. data/lib/laser/standard_library/abbrev.rb +103 -0
  92. data/lib/laser/standard_library/array.rb +418 -0
  93. data/lib/laser/standard_library/base64.rb +91 -0
  94. data/lib/laser/standard_library/basic_object.rb +55 -0
  95. data/lib/laser/standard_library/benchmark.rb +556 -0
  96. data/lib/laser/standard_library/bignum.rb +185 -0
  97. data/lib/laser/standard_library/cgi.rb +275 -0
  98. data/lib/laser/standard_library/cgi/cookie.rb +147 -0
  99. data/lib/laser/standard_library/cgi/core.rb +791 -0
  100. data/lib/laser/standard_library/cgi/html.rb +1021 -0
  101. data/lib/laser/standard_library/cgi/session.rb +537 -0
  102. data/lib/laser/standard_library/cgi/session/pstore.rb +111 -0
  103. data/lib/laser/standard_library/cgi/util.rb +188 -0
  104. data/lib/laser/standard_library/class_definitions.rb +333 -0
  105. data/lib/laser/standard_library/comparable.rb +125 -0
  106. data/lib/laser/standard_library/complex.rb +162 -0
  107. data/lib/laser/standard_library/enumerable.rb +178 -0
  108. data/lib/laser/standard_library/exceptions.rb +135 -0
  109. data/lib/laser/standard_library/fixnum.rb +188 -0
  110. data/lib/laser/standard_library/float.rb +180 -0
  111. data/lib/laser/standard_library/hash.rb +237 -0
  112. data/lib/laser/standard_library/integer.rb +123 -0
  113. data/lib/laser/standard_library/laser_magic.rb +7 -0
  114. data/lib/laser/standard_library/nil_false_true.rb +113 -0
  115. data/lib/laser/standard_library/numbers.rb +192 -0
  116. data/lib/laser/standard_library/proc.rb +31 -0
  117. data/lib/laser/standard_library/set.rb +1348 -0
  118. data/lib/laser/standard_library/string.rb +666 -0
  119. data/lib/laser/standard_library/stringio.rb +2 -0
  120. data/lib/laser/standard_library/symbol.rb +125 -0
  121. data/lib/laser/standard_library/tsort.rb +242 -0
  122. data/lib/laser/support/acts_as_struct.rb +66 -0
  123. data/lib/laser/support/frequency.rb +55 -0
  124. data/lib/laser/support/inheritable_attributes.rb +145 -0
  125. data/lib/laser/support/module_extensions.rb +94 -0
  126. data/lib/laser/support/placeholder_object.rb +13 -0
  127. data/lib/laser/third_party/rgl/adjacency.rb +221 -0
  128. data/lib/laser/third_party/rgl/base.rb +228 -0
  129. data/lib/laser/third_party/rgl/bidirectional.rb +39 -0
  130. data/lib/laser/third_party/rgl/condensation.rb +47 -0
  131. data/lib/laser/third_party/rgl/connected_components.rb +138 -0
  132. data/lib/laser/third_party/rgl/control_flow.rb +170 -0
  133. data/lib/laser/third_party/rgl/depth_first_spanning_tree.rb +37 -0
  134. data/lib/laser/third_party/rgl/dominators.rb +124 -0
  135. data/lib/laser/third_party/rgl/dot.rb +93 -0
  136. data/lib/laser/third_party/rgl/graphxml.rb +51 -0
  137. data/lib/laser/third_party/rgl/implicit.rb +174 -0
  138. data/lib/laser/third_party/rgl/mutable.rb +117 -0
  139. data/lib/laser/third_party/rgl/rdot.rb +445 -0
  140. data/lib/laser/third_party/rgl/topsort.rb +72 -0
  141. data/lib/laser/third_party/rgl/transitivity.rb +180 -0
  142. data/lib/laser/third_party/rgl/traversal.rb +348 -0
  143. data/lib/laser/types/types.rb +433 -0
  144. data/lib/laser/version.rb +14 -0
  145. data/lib/laser/warning.rb +149 -0
  146. data/lib/laser/warning_sets/default.yml +13 -0
  147. data/lib/laser/warnings/assignment_in_condition.rb +20 -0
  148. data/lib/laser/warnings/comment_spacing.rb +31 -0
  149. data/lib/laser/warnings/extra_blank_lines.rb +30 -0
  150. data/lib/laser/warnings/extra_whitespace.rb +16 -0
  151. data/lib/laser/warnings/hash_symbol_18_warning.rb +63 -0
  152. data/lib/laser/warnings/hash_symbol_19_warning.rb +29 -0
  153. data/lib/laser/warnings/line_length.rb +115 -0
  154. data/lib/laser/warnings/misaligned_unindentation.rb +17 -0
  155. data/lib/laser/warnings/operator_spacing.rb +68 -0
  156. data/lib/laser/warnings/parens_on_declaration.rb +30 -0
  157. data/lib/laser/warnings/rescue_exception.rb +42 -0
  158. data/lib/laser/warnings/semicolon.rb +25 -0
  159. data/lib/laser/warnings/sexp_errors.rb +24 -0
  160. data/lib/laser/warnings/uncalled_method_warning.rb +7 -0
  161. data/lib/laser/warnings/useless_double_quotes.rb +38 -0
  162. data/spec/analysis_specs/annotations_spec.rb +47 -0
  163. data/spec/analysis_specs/annotations_specs/comment_attachment_spec.rb +68 -0
  164. data/spec/analysis_specs/annotations_specs/node_pointers_annotation_spec.rb +90 -0
  165. data/spec/analysis_specs/annotations_specs/runtime_annotation_spec.rb +135 -0
  166. data/spec/analysis_specs/annotations_specs/spec_helper.rb +33 -0
  167. data/spec/analysis_specs/argument_expansion_spec.rb +113 -0
  168. data/spec/analysis_specs/bindings_spec.rb +36 -0
  169. data/spec/analysis_specs/comment_spec.rb +93 -0
  170. data/spec/analysis_specs/control_flow_specs/cfg_instruction_spec.rb +111 -0
  171. data/spec/analysis_specs/control_flow_specs/constant_propagation_spec.rb +560 -0
  172. data/spec/analysis_specs/control_flow_specs/control_flow_graph_spec.rb +5 -0
  173. data/spec/analysis_specs/control_flow_specs/raise_properties_spec.rb +310 -0
  174. data/spec/analysis_specs/control_flow_specs/raise_type_inference_spec.rb +301 -0
  175. data/spec/analysis_specs/control_flow_specs/return_type_inference_spec.rb +431 -0
  176. data/spec/analysis_specs/control_flow_specs/simulation_spec.rb +158 -0
  177. data/spec/analysis_specs/control_flow_specs/spec_helper.rb +110 -0
  178. data/spec/analysis_specs/control_flow_specs/tuple_misuse_inference_spec.rb +125 -0
  179. data/spec/analysis_specs/control_flow_specs/unreachability_analysis_spec.rb +76 -0
  180. data/spec/analysis_specs/control_flow_specs/unused_variable_spec.rb +99 -0
  181. data/spec/analysis_specs/control_flow_specs/yield_properties_spec.rb +372 -0
  182. data/spec/analysis_specs/error_spec.rb +30 -0
  183. data/spec/analysis_specs/laser_class_spec.rb +322 -0
  184. data/spec/analysis_specs/lexical_analysis_spec.rb +184 -0
  185. data/spec/analysis_specs/protocol_registry_spec.rb +63 -0
  186. data/spec/analysis_specs/scope_annotation_spec.rb +1013 -0
  187. data/spec/analysis_specs/scope_spec.rb +126 -0
  188. data/spec/analysis_specs/sexp_analysis_spec.rb +30 -0
  189. data/spec/analysis_specs/sexp_extension_specs/constant_extraction_spec.rb +309 -0
  190. data/spec/analysis_specs/sexp_extension_specs/source_location_spec.rb +231 -0
  191. data/spec/analysis_specs/sexp_extension_specs/spec_helper.rb +1 -0
  192. data/spec/analysis_specs/sexp_extension_specs/type_inference_spec.rb +252 -0
  193. data/spec/analysis_specs/sexp_spec.rb +167 -0
  194. data/spec/analysis_specs/spec_helper.rb +27 -0
  195. data/spec/analysis_specs/unused_methods_spec.rb +65 -0
  196. data/spec/analysis_specs/visitor_spec.rb +64 -0
  197. data/spec/annotation_parser_specs/annotations_parser_spec.rb +89 -0
  198. data/spec/annotation_parser_specs/class_annotation_parser_spec.rb +120 -0
  199. data/spec/annotation_parser_specs/overload_parser_spec.rb +39 -0
  200. data/spec/annotation_parser_specs/parsers_spec.rb +14 -0
  201. data/spec/annotation_parser_specs/spec_helper.rb +1 -0
  202. data/spec/annotation_parser_specs/structural_parser_spec.rb +67 -0
  203. data/spec/laser_spec.rb +14 -0
  204. data/spec/rake_specs/spec_helper.rb +1 -0
  205. data/spec/rake_specs/task_spec.rb +67 -0
  206. data/spec/runner_spec.rb +207 -0
  207. data/spec/scanner_spec.rb +75 -0
  208. data/spec/spec_helper.rb +121 -0
  209. data/spec/standard_library/exceptions_spec.rb +19 -0
  210. data/spec/standard_library/globals_spec.rb +14 -0
  211. data/spec/standard_library/set_spec.rb +31 -0
  212. data/spec/standard_library/spec_helper.rb +1 -0
  213. data/spec/standard_library/standard_library_spec.rb +302 -0
  214. data/spec/support_specs/acts_as_struct_spec.rb +94 -0
  215. data/spec/support_specs/frequency_spec.rb +23 -0
  216. data/spec/support_specs/module_extensions_spec.rb +117 -0
  217. data/spec/support_specs/spec_helper.rb +1 -0
  218. data/spec/type_specs/spec_helper.rb +1 -0
  219. data/spec/type_specs/types_spec.rb +133 -0
  220. data/spec/warning_spec.rb +95 -0
  221. data/spec/warning_specs/assignment_in_condition_spec.rb +68 -0
  222. data/spec/warning_specs/comment_spacing_spec.rb +65 -0
  223. data/spec/warning_specs/extra_blank_lines_spec.rb +70 -0
  224. data/spec/warning_specs/extra_whitespace_spec.rb +33 -0
  225. data/spec/warning_specs/hash_symbol_18_warning_spec.rb +89 -0
  226. data/spec/warning_specs/hash_symbol_19_warning_spec.rb +63 -0
  227. data/spec/warning_specs/line_length_spec.rb +173 -0
  228. data/spec/warning_specs/misaligned_unindentation_spec.rb +35 -0
  229. data/spec/warning_specs/operator_spacing_spec.rb +104 -0
  230. data/spec/warning_specs/parens_on_declaration_spec.rb +57 -0
  231. data/spec/warning_specs/rescue_exception_spec.rb +105 -0
  232. data/spec/warning_specs/semicolon_spec.rb +58 -0
  233. data/spec/warning_specs/spec_helper.rb +1 -0
  234. data/spec/warning_specs/useless_double_quotes_spec.rb +74 -0
  235. data/status_reports/2010/12/2010-12-14.md +163 -0
  236. data/status_reports/2010/12/2010-12-23.md +298 -0
  237. data/status_reports/2010/12/2010-12-24.md +6 -0
  238. data/test/third_party_tests/rgl_tests/TestComponents.rb +65 -0
  239. data/test/third_party_tests/rgl_tests/TestCycles.rb +61 -0
  240. data/test/third_party_tests/rgl_tests/TestDirectedGraph.rb +125 -0
  241. data/test/third_party_tests/rgl_tests/TestDot.rb +18 -0
  242. data/test/third_party_tests/rgl_tests/TestEdge.rb +34 -0
  243. data/test/third_party_tests/rgl_tests/TestGraph.rb +71 -0
  244. data/test/third_party_tests/rgl_tests/TestGraphXML.rb +57 -0
  245. data/test/third_party_tests/rgl_tests/TestImplicit.rb +52 -0
  246. data/test/third_party_tests/rgl_tests/TestRdot.rb +863 -0
  247. data/test/third_party_tests/rgl_tests/TestTransitivity.rb +129 -0
  248. data/test/third_party_tests/rgl_tests/TestTraversal.rb +220 -0
  249. data/test/third_party_tests/rgl_tests/TestUnDirectedGraph.rb +102 -0
  250. data/test/third_party_tests/rgl_tests/examples/north/Graph.log +128 -0
  251. data/test/third_party_tests/rgl_tests/examples/north/g.10.0.graphml +28 -0
  252. data/test/third_party_tests/rgl_tests/examples/north/g.10.1.graphml +28 -0
  253. data/test/third_party_tests/rgl_tests/examples/north/g.10.11.graphml +31 -0
  254. data/test/third_party_tests/rgl_tests/examples/north/g.10.12.graphml +27 -0
  255. data/test/third_party_tests/rgl_tests/examples/north/g.10.13.graphml +27 -0
  256. data/test/third_party_tests/rgl_tests/examples/north/g.10.14.graphml +27 -0
  257. data/test/third_party_tests/rgl_tests/examples/north/g.10.15.graphml +26 -0
  258. data/test/third_party_tests/rgl_tests/examples/north/g.10.16.graphml +26 -0
  259. data/test/third_party_tests/rgl_tests/examples/north/g.10.17.graphml +26 -0
  260. data/test/third_party_tests/rgl_tests/examples/north/g.10.19.graphml +37 -0
  261. data/test/third_party_tests/rgl_tests/examples/north/g.10.2.graphml +28 -0
  262. data/test/third_party_tests/rgl_tests/examples/north/g.10.20.graphml +38 -0
  263. data/test/third_party_tests/rgl_tests/examples/north/g.10.22.graphml +43 -0
  264. data/test/third_party_tests/rgl_tests/examples/north/g.10.24.graphml +30 -0
  265. data/test/third_party_tests/rgl_tests/examples/north/g.10.25.graphml +45 -0
  266. data/test/third_party_tests/rgl_tests/examples/north/g.10.27.graphml +38 -0
  267. data/test/third_party_tests/rgl_tests/examples/north/g.10.28.graphml +30 -0
  268. data/test/third_party_tests/rgl_tests/examples/north/g.10.29.graphml +38 -0
  269. data/test/third_party_tests/rgl_tests/examples/north/g.10.3.graphml +26 -0
  270. data/test/third_party_tests/rgl_tests/examples/north/g.10.30.graphml +34 -0
  271. data/test/third_party_tests/rgl_tests/examples/north/g.10.31.graphml +42 -0
  272. data/test/third_party_tests/rgl_tests/examples/north/g.10.34.graphml +42 -0
  273. data/test/third_party_tests/rgl_tests/examples/north/g.10.37.graphml +28 -0
  274. data/test/third_party_tests/rgl_tests/examples/north/g.10.38.graphml +38 -0
  275. data/test/third_party_tests/rgl_tests/examples/north/g.10.39.graphml +36 -0
  276. data/test/third_party_tests/rgl_tests/examples/north/g.10.4.graphml +26 -0
  277. data/test/third_party_tests/rgl_tests/examples/north/g.10.40.graphml +37 -0
  278. data/test/third_party_tests/rgl_tests/examples/north/g.10.41.graphml +37 -0
  279. data/test/third_party_tests/rgl_tests/examples/north/g.10.42.graphml +26 -0
  280. data/test/third_party_tests/rgl_tests/examples/north/g.10.45.graphml +28 -0
  281. data/test/third_party_tests/rgl_tests/examples/north/g.10.46.graphml +32 -0
  282. data/test/third_party_tests/rgl_tests/examples/north/g.10.5.graphml +31 -0
  283. data/test/third_party_tests/rgl_tests/examples/north/g.10.50.graphml +30 -0
  284. data/test/third_party_tests/rgl_tests/examples/north/g.10.56.graphml +29 -0
  285. data/test/third_party_tests/rgl_tests/examples/north/g.10.57.graphml +32 -0
  286. data/test/third_party_tests/rgl_tests/examples/north/g.10.58.graphml +32 -0
  287. data/test/third_party_tests/rgl_tests/examples/north/g.10.6.graphml +26 -0
  288. data/test/third_party_tests/rgl_tests/examples/north/g.10.60.graphml +32 -0
  289. data/test/third_party_tests/rgl_tests/examples/north/g.10.61.graphml +34 -0
  290. data/test/third_party_tests/rgl_tests/examples/north/g.10.62.graphml +34 -0
  291. data/test/third_party_tests/rgl_tests/examples/north/g.10.68.graphml +30 -0
  292. data/test/third_party_tests/rgl_tests/examples/north/g.10.69.graphml +32 -0
  293. data/test/third_party_tests/rgl_tests/examples/north/g.10.7.graphml +29 -0
  294. data/test/third_party_tests/rgl_tests/examples/north/g.10.70.graphml +26 -0
  295. data/test/third_party_tests/rgl_tests/examples/north/g.10.71.graphml +27 -0
  296. data/test/third_party_tests/rgl_tests/examples/north/g.10.72.graphml +28 -0
  297. data/test/third_party_tests/rgl_tests/examples/north/g.10.74.graphml +29 -0
  298. data/test/third_party_tests/rgl_tests/examples/north/g.10.75.graphml +29 -0
  299. data/test/third_party_tests/rgl_tests/examples/north/g.10.78.graphml +27 -0
  300. data/test/third_party_tests/rgl_tests/examples/north/g.10.79.graphml +34 -0
  301. data/test/third_party_tests/rgl_tests/examples/north/g.10.8.graphml +29 -0
  302. data/test/third_party_tests/rgl_tests/examples/north/g.10.80.graphml +34 -0
  303. data/test/third_party_tests/rgl_tests/examples/north/g.10.82.graphml +35 -0
  304. data/test/third_party_tests/rgl_tests/examples/north/g.10.83.graphml +32 -0
  305. data/test/third_party_tests/rgl_tests/examples/north/g.10.85.graphml +34 -0
  306. data/test/third_party_tests/rgl_tests/examples/north/g.10.86.graphml +34 -0
  307. data/test/third_party_tests/rgl_tests/examples/north/g.10.88.graphml +37 -0
  308. data/test/third_party_tests/rgl_tests/examples/north/g.10.89.graphml +29 -0
  309. data/test/third_party_tests/rgl_tests/examples/north/g.10.9.graphml +26 -0
  310. data/test/third_party_tests/rgl_tests/examples/north/g.10.90.graphml +32 -0
  311. data/test/third_party_tests/rgl_tests/examples/north/g.10.91.graphml +31 -0
  312. data/test/third_party_tests/rgl_tests/examples/north/g.10.92.graphml +26 -0
  313. data/test/third_party_tests/rgl_tests/examples/north/g.10.93.graphml +32 -0
  314. data/test/third_party_tests/rgl_tests/examples/north/g.10.94.graphml +34 -0
  315. data/test/third_party_tests/rgl_tests/examples/north/g.12.8.graphml +40 -0
  316. data/test/third_party_tests/rgl_tests/examples/north/g.14.9.graphml +36 -0
  317. data/test/third_party_tests/rgl_tests/test_helper.rb +7 -0
  318. data/test/third_party_tests/test_inheritable_attributes.rb +187 -0
  319. metadata +470 -0
@@ -0,0 +1,91 @@
1
+ #
2
+ # = base64.rb: methods for base64-encoding and -decoding strings
3
+ #
4
+
5
+ # The Base64 module provides for the encoding (#encode64, #strict_encode64,
6
+ # #urlsafe_encode64) and decoding (#decode64, #strict_decode64,
7
+ # #urlsafe_decode64) of binary data using a Base64 representation.
8
+ #
9
+ # == Example
10
+ #
11
+ # A simple encoding and decoding.
12
+ #
13
+ # require "base64"
14
+ #
15
+ # enc = Base64.encode64('Send reinforcements')
16
+ # # -> "U2VuZCByZWluZm9yY2VtZW50cw==\n"
17
+ # plain = Base64.decode64(enc)
18
+ # # -> "Send reinforcements"
19
+ #
20
+ # The purpose of using base64 to encode data is that it translates any
21
+ # binary data into purely printable characters.
22
+
23
+ module Base64
24
+ module_function
25
+
26
+ # Returns the Base64-encoded version of +bin+.
27
+ # This method complies with RFC 2045.
28
+ # Line feeds are added to every 60 encoded charactors.
29
+ #
30
+ # require 'base64'
31
+ # Base64.encode64("Now is the time for all good coders\nto learn Ruby")
32
+ #
33
+ # <i>Generates:</i>
34
+ #
35
+ # Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g
36
+ # UnVieQ==
37
+ def encode64(bin)
38
+ [bin].pack("m")
39
+ end
40
+
41
+ # Returns the Base64-decoded version of +str+.
42
+ # This method complies with RFC 2045.
43
+ # Characters outside the base alphabet are ignored.
44
+ #
45
+ # require 'base64'
46
+ # str = 'VGhpcyBpcyBsaW5lIG9uZQpUaGlzIG' +
47
+ # 'lzIGxpbmUgdHdvClRoaXMgaXMgbGlu' +
48
+ # 'ZSB0aHJlZQpBbmQgc28gb24uLi4K'
49
+ # puts Base64.decode64(str)
50
+ #
51
+ # <i>Generates:</i>
52
+ #
53
+ # This is line one
54
+ # This is line two
55
+ # This is line three
56
+ # And so on...
57
+ def decode64(str)
58
+ str.unpack("m").first
59
+ end
60
+
61
+ # Returns the Base64-encoded version of +bin+.
62
+ # This method complies with RFC 4648.
63
+ # No line feeds are added.
64
+ def strict_encode64(bin)
65
+ [bin].pack("m0")
66
+ end
67
+
68
+ # Returns the Base64-decoded version of +str+.
69
+ # This method complies with RFC 4648.
70
+ # ArgumentError is raised if +str+ is incorrectly padded or contains
71
+ # non-alphabet characters. Note that CR or LF are also rejected.
72
+ def strict_decode64(str)
73
+ str.unpack("m0").first
74
+ end
75
+
76
+ # Returns the Base64-encoded version of +bin+.
77
+ # This method complies with ``Base 64 Encoding with URL and Filename Safe
78
+ # Alphabet'' in RFC 4648.
79
+ # The alphabet uses '-' instead of '+' and '_' instead of '/'.
80
+ def urlsafe_encode64(bin)
81
+ strict_encode64(bin).tr("+/", "-_")
82
+ end
83
+
84
+ # Returns the Base64-decoded version of +str+.
85
+ # This method complies with ``Base 64 Encoding with URL and Filename Safe
86
+ # Alphabet'' in RFC 4648.
87
+ # The alphabet uses '-' instead of '+' and '_' instead of '/'.
88
+ def urlsafe_decode64(str)
89
+ strict_decode64(str.tr("-_", "+/"))
90
+ end
91
+ end
@@ -0,0 +1,55 @@
1
+ class BasicObject < nil
2
+ # pure: true
3
+ # raises: never
4
+ # builtin: true
5
+ def !
6
+ end
7
+ # pure: true
8
+ # raises: never
9
+ # builtin: true
10
+ # returns: Boolean
11
+ def ==(other)
12
+ end
13
+ # pure: true
14
+ # raises: never
15
+ # builtin: true
16
+ # returns: Boolean
17
+ def !=(other)
18
+ end
19
+ # builtin: true
20
+ def __send__(msg, *args, &blk)
21
+ end
22
+ # builtin: true
23
+ # pure: true
24
+ # raises: false
25
+ def equal?(other)
26
+ end
27
+ # builtin: true
28
+ def instance_eval(code = :__not_given__, file='(eval)', line=1)
29
+ end
30
+ # builtin: true
31
+ def instance_exec(*args)
32
+ end
33
+
34
+ private
35
+
36
+ # pure: true
37
+ # raises: false
38
+ def initialize(*args)
39
+ end
40
+ # builtin: true
41
+ # raises: always
42
+ def method_missing(symbol, *args, &blk)
43
+ raise ::NoMethodError.new("undefined method #{symbol} for me.")
44
+ end
45
+ # builtin: true
46
+ def singleton_method_added(symbol)
47
+ end
48
+ # builtin: true
49
+ def singleton_method_removed(symbol)
50
+ end
51
+ # builtin: true
52
+ def singleton_method_undefined(symbol)
53
+ end
54
+
55
+ end
@@ -0,0 +1,556 @@
1
+ =begin
2
+ #
3
+ # benchmark.rb - a performance benchmarking library
4
+ #
5
+ # $Id: benchmark.rb 30747 2011-01-31 16:11:06Z naruse $
6
+ #
7
+ # Created by Gotoken (gotoken@notwork.org).
8
+ #
9
+ # Documentation by Gotoken (original RD), Lyle Johnson (RDoc conversion), and
10
+ # Gavin Sinclair (editing).
11
+ #
12
+ =end
13
+
14
+ # == Overview
15
+ #
16
+ # The Benchmark module provides methods for benchmarking Ruby code, giving
17
+ # detailed reports on the time taken for each task.
18
+ #
19
+
20
+ # The Benchmark module provides methods to measure and report the time
21
+ # used to execute Ruby code.
22
+ #
23
+ # * Measure the time to construct the string given by the expression
24
+ # <tt>"a"*1_000_000</tt>:
25
+ #
26
+ # require 'benchmark'
27
+ #
28
+ # puts Benchmark.measure { "a"*1_000_000 }
29
+ #
30
+ # On my machine (FreeBSD 3.2 on P5, 100MHz) this generates:
31
+ #
32
+ # 1.166667 0.050000 1.216667 ( 0.571355)
33
+ #
34
+ # This report shows the user CPU time, system CPU time, the sum of
35
+ # the user and system CPU times, and the elapsed real time. The unit
36
+ # of time is seconds.
37
+ #
38
+ # * Do some experiments sequentially using the #bm method:
39
+ #
40
+ # require 'benchmark'
41
+ #
42
+ # n = 50000
43
+ # Benchmark.bm do |x|
44
+ # x.report { for i in 1..n; a = "1"; end }
45
+ # x.report { n.times do ; a = "1"; end }
46
+ # x.report { 1.upto(n) do ; a = "1"; end }
47
+ # end
48
+ #
49
+ # The result:
50
+ #
51
+ # user system total real
52
+ # 1.033333 0.016667 1.016667 ( 0.492106)
53
+ # 1.483333 0.000000 1.483333 ( 0.694605)
54
+ # 1.516667 0.000000 1.516667 ( 0.711077)
55
+ #
56
+ # * Continuing the previous example, put a label in each report:
57
+ #
58
+ # require 'benchmark'
59
+ #
60
+ # n = 50000
61
+ # Benchmark.bm(7) do |x|
62
+ # x.report("for:") { for i in 1..n; a = "1"; end }
63
+ # x.report("times:") { n.times do ; a = "1"; end }
64
+ # x.report("upto:") { 1.upto(n) do ; a = "1"; end }
65
+ # end
66
+ #
67
+ # The result:
68
+ #
69
+ # user system total real
70
+ # for: 1.050000 0.000000 1.050000 ( 0.503462)
71
+ # times: 1.533333 0.016667 1.550000 ( 0.735473)
72
+ # upto: 1.500000 0.016667 1.516667 ( 0.711239)
73
+ #
74
+ #
75
+ # * The times for some benchmarks depend on the order in which items
76
+ # are run. These differences are due to the cost of memory
77
+ # allocation and garbage collection. To avoid these discrepancies,
78
+ # the #bmbm method is provided. For example, to compare ways to
79
+ # sort an array of floats:
80
+ #
81
+ # require 'benchmark'
82
+ #
83
+ # array = (1..1000000).map { rand }
84
+ #
85
+ # Benchmark.bmbm do |x|
86
+ # x.report("sort!") { array.dup.sort! }
87
+ # x.report("sort") { array.dup.sort }
88
+ # end
89
+ #
90
+ # The result:
91
+ #
92
+ # Rehearsal -----------------------------------------
93
+ # sort! 11.928000 0.010000 11.938000 ( 12.756000)
94
+ # sort 13.048000 0.020000 13.068000 ( 13.857000)
95
+ # ------------------------------- total: 25.006000sec
96
+ #
97
+ # user system total real
98
+ # sort! 12.959000 0.010000 12.969000 ( 13.793000)
99
+ # sort 12.007000 0.000000 12.007000 ( 12.791000)
100
+ #
101
+ #
102
+ # * Report statistics of sequential experiments with unique labels,
103
+ # using the #benchmark method:
104
+ #
105
+ # require 'benchmark'
106
+ # include Benchmark # we need the CAPTION and FORMAT constants
107
+ #
108
+ # n = 50000
109
+ # Benchmark.benchmark(CAPTION, 7, FORMAT, ">total:", ">avg:") do |x|
110
+ # tf = x.report("for:") { for i in 1..n; a = "1"; end }
111
+ # tt = x.report("times:") { n.times do ; a = "1"; end }
112
+ # tu = x.report("upto:") { 1.upto(n) do ; a = "1"; end }
113
+ # [tf+tt+tu, (tf+tt+tu)/3]
114
+ # end
115
+ #
116
+ # The result:
117
+ #
118
+ # user system total real
119
+ # for: 1.016667 0.016667 1.033333 ( 0.485749)
120
+ # times: 1.450000 0.016667 1.466667 ( 0.681367)
121
+ # upto: 1.533333 0.000000 1.533333 ( 0.722166)
122
+ # >total: 4.000000 0.033333 4.033333 ( 1.889282)
123
+ # >avg: 1.333333 0.011111 1.344444 ( 0.629761)
124
+
125
+ module Benchmark
126
+
127
+ BENCHMARK_VERSION = "2002-04-25" #:nodoc"
128
+
129
+ # Invokes the block with a <tt>Benchmark::Report</tt> object, which
130
+ # may be used to collect and report on the results of individual
131
+ # benchmark tests. Reserves <i>label_width</i> leading spaces for
132
+ # labels on each line. Prints _caption_ at the top of the
133
+ # report, and uses _format_ to format each line.
134
+ # Returns an array of Benchmark::Tms objects.
135
+ #
136
+ # If the block returns an array of
137
+ # <tt>Benchmark::Tms</tt> objects, these will be used to format
138
+ # additional lines of output. If _label_ parameters are
139
+ # given, these are used to label these extra lines.
140
+ #
141
+ # _Note_: Other methods provide a simpler interface to this one, and are
142
+ # suitable for nearly all benchmarking requirements. See the examples in
143
+ # Benchmark, and the #bm and #bmbm methods.
144
+ #
145
+ # Example:
146
+ #
147
+ # require 'benchmark'
148
+ # include Benchmark # we need the CAPTION and FORMAT constants
149
+ #
150
+ # n = 50000
151
+ # Benchmark.benchmark(CAPTION, 7, FORMAT, ">total:", ">avg:") do |x|
152
+ # tf = x.report("for:") { for i in 1..n; a = "1"; end }
153
+ # tt = x.report("times:") { n.times do ; a = "1"; end }
154
+ # tu = x.report("upto:") { 1.upto(n) do ; a = "1"; end }
155
+ # [tf+tt+tu, (tf+tt+tu)/3]
156
+ # end
157
+ #
158
+ # <i>Generates:</i>
159
+ #
160
+ # user system total real
161
+ # for: 1.016667 0.016667 1.033333 ( 0.485749)
162
+ # times: 1.450000 0.016667 1.466667 ( 0.681367)
163
+ # upto: 1.533333 0.000000 1.533333 ( 0.722166)
164
+ # >total: 4.000000 0.033333 4.033333 ( 1.889282)
165
+ # >avg: 1.333333 0.011111 1.344444 ( 0.629761)
166
+ #
167
+
168
+ def benchmark(caption = "", label_width = nil, format = nil, *labels) # :yield: report
169
+ sync = STDOUT.sync
170
+ STDOUT.sync = true
171
+ label_width ||= 0
172
+ format ||= FORMAT
173
+ print ' '*label_width + caption
174
+ report = Report.new(label_width, format)
175
+ results = yield(report)
176
+ Array === results and results.grep(Tms).each {|t|
177
+ print((labels.shift || t.label || "").ljust(label_width), t.format(format))
178
+ }
179
+ STDOUT.sync = sync
180
+ report.list
181
+ end
182
+
183
+
184
+ # A simple interface to the #benchmark method, #bm is generates sequential reports
185
+ # with labels. The parameters have the same meaning as for #benchmark.
186
+ #
187
+ # require 'benchmark'
188
+ #
189
+ # n = 50000
190
+ # Benchmark.bm(7) do |x|
191
+ # x.report("for:") { for i in 1..n; a = "1"; end }
192
+ # x.report("times:") { n.times do ; a = "1"; end }
193
+ # x.report("upto:") { 1.upto(n) do ; a = "1"; end }
194
+ # end
195
+ #
196
+ # <i>Generates:</i>
197
+ #
198
+ # user system total real
199
+ # for: 1.050000 0.000000 1.050000 ( 0.503462)
200
+ # times: 1.533333 0.016667 1.550000 ( 0.735473)
201
+ # upto: 1.500000 0.016667 1.516667 ( 0.711239)
202
+ #
203
+
204
+ def bm(label_width = 0, *labels, &blk) # :yield: report
205
+ benchmark(CAPTION, label_width, FORMAT, *labels, &blk)
206
+ end
207
+
208
+
209
+ # Sometimes benchmark results are skewed because code executed
210
+ # earlier encounters different garbage collection overheads than
211
+ # that run later. #bmbm attempts to minimize this effect by running
212
+ # the tests twice, the first time as a rehearsal in order to get the
213
+ # runtime environment stable, the second time for
214
+ # real. <tt>GC.start</tt> is executed before the start of each of
215
+ # the real timings; the cost of this is not included in the
216
+ # timings. In reality, though, there's only so much that #bmbm can
217
+ # do, and the results are not guaranteed to be isolated from garbage
218
+ # collection and other effects.
219
+ #
220
+ # Because #bmbm takes two passes through the tests, it can
221
+ # calculate the required label width.
222
+ #
223
+ # require 'benchmark'
224
+ #
225
+ # array = (1..1000000).map { rand }
226
+ #
227
+ # Benchmark.bmbm do |x|
228
+ # x.report("sort!") { array.dup.sort! }
229
+ # x.report("sort") { array.dup.sort }
230
+ # end
231
+ #
232
+ # <i>Generates:</i>
233
+ #
234
+ # Rehearsal -----------------------------------------
235
+ # sort! 11.928000 0.010000 11.938000 ( 12.756000)
236
+ # sort 13.048000 0.020000 13.068000 ( 13.857000)
237
+ # ------------------------------- total: 25.006000sec
238
+ #
239
+ # user system total real
240
+ # sort! 12.959000 0.010000 12.969000 ( 13.793000)
241
+ # sort 12.007000 0.000000 12.007000 ( 12.791000)
242
+ #
243
+ # #bmbm yields a Benchmark::Job object and returns an array of
244
+ # Benchmark::Tms objects.
245
+ #
246
+ def bmbm(width = 0, &blk) # :yield: job
247
+ job = Job.new(width)
248
+ yield(job)
249
+ width = job.width
250
+ sync = STDOUT.sync
251
+ STDOUT.sync = true
252
+
253
+ # rehearsal
254
+ puts 'Rehearsal '.ljust(width+CAPTION.length,'-')
255
+ ets = job.list.inject(Tms.new) { |sum,(label,item)|
256
+ print label.ljust(width)
257
+ res = Benchmark.measure(&item)
258
+ print res.format
259
+ sum + res
260
+ }.format("total: %tsec")
261
+ print " #{ets}\n\n".rjust(width+CAPTION.length+2,'-')
262
+
263
+ # take
264
+ print ' '*width + CAPTION
265
+ job.list.map { |label,item|
266
+ GC.start
267
+ print label.ljust(width)
268
+ Benchmark.measure(&item).tap { |res| print res.format }
269
+ }.tap {
270
+ STDOUT.sync = sync
271
+ }
272
+ end
273
+
274
+ #
275
+ # Returns the time used to execute the given block as a
276
+ # Benchmark::Tms object.
277
+ #
278
+ def measure(label = "") # :yield:
279
+ t0, r0 = Process.times, Time.now
280
+ yield
281
+ t1, r1 = Process.times, Time.now
282
+ Benchmark::Tms.new(t1.utime - t0.utime,
283
+ t1.stime - t0.stime,
284
+ t1.cutime - t0.cutime,
285
+ t1.cstime - t0.cstime,
286
+ r1.to_f - r0.to_f,
287
+ label)
288
+ end
289
+
290
+ #
291
+ # Returns the elapsed real time used to execute the given block.
292
+ #
293
+ def realtime(&blk) # :yield:
294
+ r0 = Time.now
295
+ yield
296
+ Time.now - r0
297
+ end
298
+
299
+ module_function :benchmark, :measure, :realtime, :bm, :bmbm
300
+
301
+ #
302
+ # A Job is a sequence of labelled blocks to be processed by the
303
+ # Benchmark.bmbm method. It is of little direct interest to the user.
304
+ #
305
+ class Job # :nodoc:
306
+ #
307
+ # Returns an initialized Job instance.
308
+ # Usually, one doesn't call this method directly, as new
309
+ # Job objects are created by the #bmbm method.
310
+ # _width_ is a initial value for the label offset used in formatting;
311
+ # the #bmbm method passes its _width_ argument to this constructor.
312
+ #
313
+ def initialize(width)
314
+ @width = width
315
+ @list = []
316
+ end
317
+
318
+ #
319
+ # Registers the given label and block pair in the job list.
320
+ #
321
+ def item(label = "", &blk) # :yield:
322
+ raise ArgumentError, "no block" unless block_given?
323
+ label = label.to_s
324
+ w = label.length
325
+ @width = w if @width < w
326
+ @list << [label, blk]
327
+ self
328
+ end
329
+
330
+ alias report item
331
+
332
+ # An array of 2-element arrays, consisting of label and block pairs.
333
+ attr_reader :list
334
+
335
+ # Length of the widest label in the #list.
336
+ attr_reader :width
337
+ end
338
+
339
+ #
340
+ # This class is used by the Benchmark.benchmark and Benchmark.bm methods.
341
+ # It is of little direct interest to the user.
342
+ #
343
+ class Report # :nodoc:
344
+ #
345
+ # Returns an initialized Report instance.
346
+ # Usually, one doesn't call this method directly, as new
347
+ # Report objects are created by the #benchmark and #bm methods.
348
+ # _width_ and _format_ are the label offset and
349
+ # format string used by Tms#format.
350
+ #
351
+ def initialize(width = 0, format = nil)
352
+ @width, @format, @list = width, format, []
353
+ end
354
+
355
+ #
356
+ # Prints the _label_ and measured time for the block,
357
+ # formatted by _format_. See Tms#format for the
358
+ # formatting rules.
359
+ #
360
+ def item(label = "", *format, &blk) # :yield:
361
+ print label.to_s.ljust(@width)
362
+ @list << res = Benchmark.measure(label, &blk)
363
+ print res.format(@format, *format)
364
+ res
365
+ end
366
+
367
+ alias report item
368
+
369
+ # An array of Benchmark::Tms objects representing each item.
370
+ attr_reader :list
371
+ end
372
+
373
+
374
+
375
+ #
376
+ # A data object, representing the times associated with a benchmark
377
+ # measurement.
378
+ #
379
+ class Tms
380
+ CAPTION = " user system total real\n"
381
+ FORMAT = "%10.6u %10.6y %10.6t %10.6r\n"
382
+
383
+ # User CPU time
384
+ attr_reader :utime
385
+
386
+ # System CPU time
387
+ attr_reader :stime
388
+
389
+ # User CPU time of children
390
+ attr_reader :cutime
391
+
392
+ # System CPU time of children
393
+ attr_reader :cstime
394
+
395
+ # Elapsed real time
396
+ attr_reader :real
397
+
398
+ # Total time, that is _utime_ + _stime_ + _cutime_ + _cstime_
399
+ attr_reader :total
400
+
401
+ # Label
402
+ attr_reader :label
403
+
404
+ #
405
+ # Returns an initialized Tms object which has
406
+ # _utime_ as the user CPU time, _stime_ as the system CPU time,
407
+ # _cutime_ as the children's user CPU time, _cstime_ as the children's
408
+ # system CPU time, _real_ as the elapsed real time and _label_ as the label.
409
+ #
410
+ def initialize(utime = 0.0, stime = 0.0, cutime = 0.0, cstime = 0.0, real = 0.0, label = nil)
411
+ @utime, @stime, @cutime, @cstime, @real, @label = utime, stime, cutime, cstime, real, label.to_s
412
+ @total = @utime + @stime + @cutime + @cstime
413
+ end
414
+
415
+ #
416
+ # Returns a new Tms object whose times are the sum of the times for this
417
+ # Tms object, plus the time required to execute the code block (_blk_).
418
+ #
419
+ def add(&blk) # :yield:
420
+ self + Benchmark.measure(&blk)
421
+ end
422
+
423
+ #
424
+ # An in-place version of #add.
425
+ #
426
+ def add!(&blk)
427
+ t = Benchmark.measure(&blk)
428
+ @utime = utime + t.utime
429
+ @stime = stime + t.stime
430
+ @cutime = cutime + t.cutime
431
+ @cstime = cstime + t.cstime
432
+ @real = real + t.real
433
+ self
434
+ end
435
+
436
+ #
437
+ # Returns a new Tms object obtained by memberwise summation
438
+ # of the individual times for this Tms object with those of the other
439
+ # Tms object.
440
+ # This method and #/() are useful for taking statistics.
441
+ #
442
+ def +(other); memberwise(:+, other) end
443
+
444
+ #
445
+ # Returns a new Tms object obtained by memberwise subtraction
446
+ # of the individual times for the other Tms object from those of this
447
+ # Tms object.
448
+ #
449
+ def -(other); memberwise(:-, other) end
450
+
451
+ #
452
+ # Returns a new Tms object obtained by memberwise multiplication
453
+ # of the individual times for this Tms object by _x_.
454
+ #
455
+ def *(x); memberwise(:*, x) end
456
+
457
+ #
458
+ # Returns a new Tms object obtained by memberwise division
459
+ # of the individual times for this Tms object by _x_.
460
+ # This method and #+() are useful for taking statistics.
461
+ #
462
+ def /(x); memberwise(:/, x) end
463
+
464
+ #
465
+ # Returns the contents of this Tms object as
466
+ # a formatted string, according to a format string
467
+ # like that passed to Kernel.format. In addition, #format
468
+ # accepts the following extensions:
469
+ #
470
+ # <tt>%u</tt>:: Replaced by the user CPU time, as reported by Tms#utime.
471
+ # <tt>%y</tt>:: Replaced by the system CPU time, as reported by #stime (Mnemonic: y of "s*y*stem")
472
+ # <tt>%U</tt>:: Replaced by the children's user CPU time, as reported by Tms#cutime
473
+ # <tt>%Y</tt>:: Replaced by the children's system CPU time, as reported by Tms#cstime
474
+ # <tt>%t</tt>:: Replaced by the total CPU time, as reported by Tms#total
475
+ # <tt>%r</tt>:: Replaced by the elapsed real time, as reported by Tms#real
476
+ # <tt>%n</tt>:: Replaced by the label string, as reported by Tms#label (Mnemonic: n of "*n*ame")
477
+ #
478
+ # If _format_ is not given, FORMAT is used as default value, detailing the
479
+ # user, system and real elapsed time.
480
+ #
481
+ def format(format = nil, *args)
482
+ str = (format || FORMAT).dup
483
+ str.gsub!(/(%[-+\.\d]*)n/) { "#{$1}s" % label }
484
+ str.gsub!(/(%[-+\.\d]*)u/) { "#{$1}f" % utime }
485
+ str.gsub!(/(%[-+\.\d]*)y/) { "#{$1}f" % stime }
486
+ str.gsub!(/(%[-+\.\d]*)U/) { "#{$1}f" % cutime }
487
+ str.gsub!(/(%[-+\.\d]*)Y/) { "#{$1}f" % cstime }
488
+ str.gsub!(/(%[-+\.\d]*)t/) { "#{$1}f" % total }
489
+ str.gsub!(/(%[-+\.\d]*)r/) { "(#{$1}f)" % real }
490
+ format ? str % args : str
491
+ end
492
+
493
+ #
494
+ # Same as #format.
495
+ #
496
+ def to_s
497
+ format
498
+ end
499
+
500
+ #
501
+ # Returns a new 6-element array, consisting of the
502
+ # label, user CPU time, system CPU time, children's
503
+ # user CPU time, children's system CPU time and elapsed
504
+ # real time.
505
+ #
506
+ def to_a
507
+ [@label, @utime, @stime, @cutime, @cstime, @real]
508
+ end
509
+
510
+ protected
511
+ def memberwise(op, x)
512
+ case x
513
+ when Benchmark::Tms
514
+ Benchmark::Tms.new(utime.__send__(op, x.utime),
515
+ stime.__send__(op, x.stime),
516
+ cutime.__send__(op, x.cutime),
517
+ cstime.__send__(op, x.cstime),
518
+ real.__send__(op, x.real)
519
+ )
520
+ else
521
+ Benchmark::Tms.new(utime.__send__(op, x),
522
+ stime.__send__(op, x),
523
+ cutime.__send__(op, x),
524
+ cstime.__send__(op, x),
525
+ real.__send__(op, x)
526
+ )
527
+ end
528
+ end
529
+ end
530
+
531
+ # The default caption string (heading above the output times).
532
+ CAPTION = Benchmark::Tms::CAPTION
533
+
534
+ # The default format string used to display times. See also Benchmark::Tms#format.
535
+ FORMAT = Benchmark::Tms::FORMAT
536
+ end
537
+
538
+ if __FILE__ == $0
539
+ include Benchmark
540
+
541
+ n = ARGV[0].to_i.nonzero? || 50000
542
+ puts %Q([#{n} times iterations of `a = "1"'])
543
+ benchmark(" " + CAPTION, 7, FORMAT) do |x|
544
+ x.report("for:") {for _ in 1..n; _ = "1"; end} # Benchmark.measure
545
+ x.report("times:") {n.times do ; _ = "1"; end}
546
+ x.report("upto:") {1.upto(n) do ; _ = "1"; end}
547
+ end
548
+
549
+ benchmark do
550
+ [
551
+ measure{for _ in 1..n; _ = "1"; end}, # Benchmark.measure
552
+ measure{n.times do ; _ = "1"; end},
553
+ measure{1.upto(n) do ; _ = "1"; end}
554
+ ]
555
+ end
556
+ end