viiite 0.1.0 → 0.2.0

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 (113) hide show
  1. data/CHANGELOG.md +70 -0
  2. data/Gemfile +2 -9
  3. data/Gemfile.lock +11 -32
  4. data/README.md +42 -123
  5. data/examples/bench_attr_vs_method-1.8.7.jpeg +0 -0
  6. data/examples/bench_attr_vs_method-1.9.3.jpeg +0 -0
  7. data/examples/bench_attr_vs_method.rb +18 -0
  8. data/examples/bench_iteration.rb +2 -4
  9. data/examples/bench_sort.rb +2 -7
  10. data/lib/viiite.rb +40 -18
  11. data/lib/viiite/bdb.rb +28 -0
  12. data/lib/viiite/bdb/cached.rb +63 -0
  13. data/lib/viiite/bdb/immediate.rb +46 -0
  14. data/lib/viiite/bdb/utils.rb +16 -0
  15. data/lib/viiite/benchmark.rb +35 -0
  16. data/lib/viiite/benchmark/runner.rb +50 -0
  17. data/lib/viiite/command.rb +33 -2
  18. data/lib/viiite/command/commons.rb +22 -0
  19. data/lib/viiite/command/help.rb +4 -5
  20. data/lib/viiite/command/plot.rb +44 -44
  21. data/lib/viiite/command/plot/to_gnuplot.rb +65 -0
  22. data/lib/viiite/command/{graph_style.rash → plot/to_gnuplot_graph.rash} +0 -0
  23. data/lib/viiite/command/{serie_style.rash → plot/to_gnuplot_serie.rash} +0 -0
  24. data/lib/viiite/command/plot/to_highcharts.rb +38 -0
  25. data/lib/viiite/command/plot/to_highcharts_graph.rb +29 -0
  26. data/lib/viiite/command/plot/to_text.rb +30 -0
  27. data/lib/viiite/command/report.rb +32 -10
  28. data/lib/viiite/command/run.rb +30 -7
  29. data/lib/viiite/errors.rb +5 -0
  30. data/lib/viiite/loader.rb +2 -2
  31. data/lib/viiite/tms.rb +21 -31
  32. data/lib/viiite/version.rb +5 -5
  33. data/spec/fixtures/bdb/Array/bench_sort.rb +7 -0
  34. data/spec/fixtures/{bench_iteration.rb → bdb/bench_iteration.rb} +2 -4
  35. data/spec/fixtures/command/bench_iteration.rb +3 -0
  36. data/spec/fixtures/saved/Array/bench_sort.rash +12 -0
  37. data/spec/fixtures/saved/bench_iteration.rash +18 -0
  38. data/spec/integration/plot/plot_1.cmd +1 -0
  39. data/spec/integration/plot/plot_1.stdout +64 -0
  40. data/spec/integration/plot/plot_2.cmd +1 -0
  41. data/spec/integration/plot/plot_2.stdout +37 -0
  42. data/spec/integration/plot/plot_3.cmd +1 -0
  43. data/spec/integration/plot/plot_3.stdout +64 -0
  44. data/spec/integration/plot/plot_4.cmd +1 -0
  45. data/spec/integration/plot/plot_4.stdout +1 -0
  46. data/spec/integration/report/viiite_report_1.cmd +1 -1
  47. data/spec/integration/report/viiite_report_1.stdout +7 -7
  48. data/spec/integration/report/viiite_report_2.cmd +1 -1
  49. data/spec/integration/report/viiite_report_2.stdout +22 -10
  50. data/spec/integration/report/viiite_report_3.cmd +1 -1
  51. data/spec/integration/report/viiite_report_3.stdout +46 -18
  52. data/spec/integration/report/viiite_report_4.cmd +1 -1
  53. data/spec/integration/report/viiite_report_4.stdout +34 -22
  54. data/spec/integration/report/viiite_report_5.cmd +1 -0
  55. data/spec/integration/report/viiite_report_5.stdout +7 -0
  56. data/spec/integration/report/viiite_report_6.cmd +1 -0
  57. data/spec/integration/report/viiite_report_6.stdout +7 -0
  58. data/spec/integration/report/viiite_report_7.cmd +1 -0
  59. data/spec/integration/report/viiite_report_7.stdout +7 -0
  60. data/spec/integration/report/viiite_report_8.cmd +1 -0
  61. data/spec/integration/report/viiite_report_8.stdout +16 -0
  62. data/spec/integration/report/viiite_report_9.cmd +1 -0
  63. data/spec/integration/report/viiite_report_9.stdout +88 -0
  64. data/spec/integration/test_command.rb +19 -23
  65. data/spec/integration/viiite/viiite_help.stdout +6 -0
  66. data/spec/spec_helper.rb +11 -17
  67. data/spec/unit/bdb/cached/test_dataset.rb +68 -0
  68. data/spec/unit/bdb/immediate/test_benchmark.rb +31 -0
  69. data/spec/unit/bdb/immediate/test_dataset.rb +31 -0
  70. data/spec/unit/bdb/immediate/test_enumerable.rb +20 -0
  71. data/spec/unit/bdb/immediate/test_pattern.rb +25 -0
  72. data/spec/unit/bdb/test_new.rb +44 -0
  73. data/spec/unit/bdb/utils/test_bench_file.rb +24 -0
  74. data/spec/unit/bdb/utils/test_replace_extension.rb +21 -0
  75. data/spec/unit/benchmark/bench_add.rb +3 -0
  76. data/spec/unit/benchmark/test_new.rb +28 -0
  77. data/spec/unit/command/commons/existing.rash +1 -0
  78. data/spec/unit/command/commons/test_single_source.rb +64 -0
  79. data/spec/unit/{formatter/plot → command/plot/gnuplot_utils}/test_to_data.rb +4 -4
  80. data/spec/unit/{formatter/plot → command/plot/gnuplot_utils}/test_to_dataset.rb +5 -5
  81. data/spec/unit/{formatter/plot → command/plot/gnuplot_utils}/test_to_plot.rb +4 -4
  82. data/spec/unit/command/test_run.rb +25 -12
  83. data/spec/unit/{test_runner.rb → test_benchmark.rb} +30 -11
  84. data/spec/unit/test_viiite.rb +17 -4
  85. data/spec/unit/tms/test_attributes.rb +11 -0
  86. data/spec/unit/tms/test_coerce.rb +11 -23
  87. data/spec/unit/tms/test_conversions.rb +23 -0
  88. data/spec/unit/tms/test_operations.rb +22 -0
  89. data/tasks/clean.rake +1 -1
  90. data/tasks/debug_mail.rake +13 -13
  91. data/tasks/gem.rake +13 -13
  92. data/tasks/integration_test.rake +3 -3
  93. data/tasks/spec_test.rake +9 -9
  94. data/tasks/unit_test.rake +9 -10
  95. data/tasks/yard.rake +13 -13
  96. data/viiite.gemspec +26 -29
  97. data/viiite.noespec +4 -7
  98. metadata +335 -235
  99. data/examples/bench_sort.eps +0 -816
  100. data/examples/bench_sort.rash +0 -100
  101. data/examples/raw.rash +0 -6
  102. data/lib/viiite/formatter.rb +0 -5
  103. data/lib/viiite/formatter/plot.rb +0 -38
  104. data/lib/viiite/runner.rb +0 -59
  105. data/lib/viiite/viiite_file.rb +0 -20
  106. data/spec/integration/raw_data.rash +0 -6
  107. data/spec/unit/tms/test_divide.rb +0 -26
  108. data/spec/unit/tms/test_minus.rb +0 -26
  109. data/spec/unit/tms/test_plus.rb +0 -34
  110. data/spec/unit/tms/test_times.rb +0 -26
  111. data/spec/unit/tms/test_to_a.rb +0 -11
  112. data/spec/unit/tms/test_to_ruby_literal.rb +0 -11
  113. data/spec/unit/tms/test_to_s.rb +0 -11
@@ -1,3 +1,73 @@
1
+ # 0.2.0
2
+
3
+ ## Awesome new features
4
+
5
+ * Viiite is now able to work on complete benchmark suites (located in
6
+ './benchmarks' and looking for '**/*.rb' files by default). Subcommands
7
+ automatically resolve benchmark names passed as arguments. For example:
8
+
9
+ ./benchmarks/
10
+ bench_iteration.rb -> viiite run bench_iteration
11
+ Array/
12
+ bench_sort.rb -> viiite run Array/bench_sort
13
+
14
+ * Default behavior remains compatible with 0.1.0:
15
+ * 'run', 'plot' and 'report' accept a benchmark file as first argument and
16
+ bypass the benchmark suite in this case.
17
+ * when invoked without any argument, 'plot' and 'report' assume a .rash stream
18
+ on standard input
19
+
20
+ * For each benchmark, the results of the last run are saved in a cache. 'plot'
21
+ and 'report' will use data in the cache if available or automatically run the
22
+ benchmark.
23
+
24
+ * The default behavior may be controlled through the following main options:
25
+ --suite=[FOLDER], --pattern=[GLOB], --[no-]cache=[FOLDER], --append, --write. Example:
26
+
27
+ # Run all benchmarks on all rubies, 10 times each, appending all results
28
+ # in cache
29
+ rvm exec viiite --append run --runs=10
30
+
31
+ ## Enhancements to individual commands
32
+
33
+ * 'viiite run'
34
+
35
+ * Added a --runs=NB option to run the same benchmark NB times. This allows
36
+ keeping benchmarks clean; no NB.times{ ... } or range_over(1..NB, :run)
37
+ for obtaining a representative sample are needed in the benchmark itself.
38
+ * The previous option comes hand-in-hand with --run-key=KEY that allows
39
+ specifying the attribute name for the run number (defaults to :run)
40
+ * Without argument, runs all the benchmarks of the suite
41
+
42
+ * 'viiite plot'
43
+
44
+ * Added --highcharts options; outputs a json array containing one hash for
45
+ each chart, to be used as options Highcharts.Chart(...) (cfr. highcharts.js)
46
+ * Added -d option, to debug; outputs the query result that would be used by
47
+ the concrete --xxx formatter.
48
+
49
+ * 'viiite report'
50
+
51
+ * output has been improved: user, system, total and real time are explicitely
52
+ shown (different attributes/columns instead of one tms measure).
53
+ * added a '--ff=FORMAT' option for float format of the different measures
54
+ (defaults to %.6f)
55
+ * added a '--stddev=[MEASURE]' option for displaying standard deviation over
56
+ all regrouped runs (on a specific measure defaulting to tms.total)
57
+
58
+ ## Other improvements
59
+
60
+ * The garbage collector is started before running report{ ... } blocks
61
+ * Viiite does not depend on benchmark (stdlib) anymore
62
+ * Improved Viiite.which_ruby; it should always output something like
63
+ '#{rubyname} #{version}#{patchlevel}' from now on
64
+
65
+ ## Bug fixes
66
+
67
+ * Fixed a bug when using 'viiite report --regroup=x,y,z --hierarchy' with more
68
+ than 2 regrouping attributes.
69
+
70
+
1
71
  # 0.1.0 / 2011-08-20
2
72
 
3
73
  * Enhancements
data/Gemfile CHANGED
@@ -11,15 +11,8 @@ group :release do
11
11
  gem "wlang", "~> 0.10.2"
12
12
  end
13
13
 
14
- group :doc do
15
- gem "yard", "~> 0.7.2"
16
- gem "bluecloth", "~> 2.1.0"
17
- gem "jekyll", "~> 0.11.0"
18
- end
19
-
20
14
  group :runtime do
21
- gem "alf", "~> 0.10.0"
22
- gem "quickl", "~> 0.4.0"
15
+ gem "alf", "~> 0.10.1"
23
16
  gem "gnuplot", "~> 2.3.6"
17
+ gem "json", ">= 0"
24
18
  end
25
-
@@ -1,32 +1,16 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- albino (1.3.3)
5
- posix-spawn (>= 0.3.6)
6
- alf (0.10.0)
7
- myrrha (~> 1.2.0)
8
- quickl (~> 0.4.0)
9
- bluecloth (2.1.0)
10
- classifier (1.3.3)
11
- fast-stemmer (>= 1.0.0)
12
- diff-lcs (1.1.2)
13
- directory_watcher (1.4.0)
14
- fast-stemmer (1.0.0)
4
+ alf (0.10.1)
5
+ highline (~> 1.6.2)
6
+ myrrha (~> 1.2.1)
7
+ quickl (~> 0.4.1)
8
+ diff-lcs (1.1.3)
15
9
  gnuplot (2.3.6)
16
- jekyll (0.11.0)
17
- albino (>= 1.3.2)
18
- classifier (>= 1.3.1)
19
- directory_watcher (>= 1.1.1)
20
- kramdown (>= 0.13.2)
21
- liquid (>= 1.9.0)
22
- maruku (>= 0.5.9)
23
- kramdown (0.13.3)
24
- liquid (2.2.2)
25
- maruku (0.6.0)
26
- syntax (>= 1.0.0)
27
- myrrha (1.2.0)
28
- posix-spawn (0.3.6)
29
- quickl (0.4.0)
10
+ highline (1.6.2)
11
+ json (1.5.3)
12
+ myrrha (1.2.1)
13
+ quickl (0.4.1)
30
14
  rake (0.9.2)
31
15
  rspec (2.6.0)
32
16
  rspec-core (~> 2.6.0)
@@ -36,20 +20,15 @@ GEM
36
20
  rspec-expectations (2.6.0)
37
21
  diff-lcs (~> 1.1.2)
38
22
  rspec-mocks (2.6.0)
39
- syntax (1.0.0)
40
23
  wlang (0.10.2)
41
- yard (0.7.2)
42
24
 
43
25
  PLATFORMS
44
26
  ruby
45
27
 
46
28
  DEPENDENCIES
47
- alf (~> 0.10.0)
48
- bluecloth (~> 2.1.0)
29
+ alf (~> 0.10.1)
49
30
  gnuplot (~> 2.3.6)
50
- jekyll (~> 0.11.0)
51
- quickl (~> 0.4.0)
31
+ json
52
32
  rake (~> 0.9.2)
53
33
  rspec (~> 2.6.0)
54
34
  wlang (~> 0.10.2)
55
- yard (~> 0.7.2)
data/README.md CHANGED
@@ -1,16 +1,16 @@
1
1
  # Viiite
2
2
 
3
- Viiite brings tools to benchmark and analyze the complexity of your algorithms.
4
- It has been designed as an alternative to Benchmark that let your benchmarks
3
+ Viiite brings tools to benchmark and analyze the complexity of your algorithms.
4
+ It has been designed as an alternative to Benchmark that let your benchmarks
5
5
  evolve smoothly from simple measures to more complex infrastructures.
6
6
 
7
7
  [sudo] gem install viiite
8
8
 
9
9
  Viiite uses [semantic versionning](http://semver.org) and has not yet reached the
10
- public API required for 1.0.0. The safe way to require viiite for now is as
10
+ public API required for 1.0.0. The safe way to require viiite for now is as
11
11
  follows:
12
12
 
13
- gem "viiite", "~> 0.1.0"
13
+ gem "viiite", "~> 0.2.0"
14
14
 
15
15
  Learn more on the [github-pages of this project](http://blambeau.github.com/viiite)!
16
16
 
@@ -22,9 +22,8 @@ Learn more on the [github-pages of this project](http://blambeau.github.com/viii
22
22
  ## From simple measures ...
23
23
 
24
24
  ```ruby
25
- require 'viiite'
26
- n = 15000
27
- Viiite.bm do |r|
25
+ Viiite.bench do |r|
26
+ n = 15000
28
27
  r.report(:for) { for i in 1..n; a = "1"; end }
29
28
  r.report(:times) { n.times do ; a = "1"; end }
30
29
  r.report(:upto) { 1.upto(n) do ; a = "1"; end }
@@ -33,22 +32,21 @@ end
33
32
 
34
33
  ```terminal
35
34
  $ viiite report bench_iteration.rb
36
- +--------+-----------------------------------------------+
37
- | :bench | :measure |
38
- +--------+-----------------------------------------------+
39
- | :for | 0.010000 0.000000 0.010000 ( 0.010454) |
40
- | :times | 0.000000 0.000000 0.000000 ( 0.002448) |
41
- | :upto | 0.000000 0.000000 0.000000 ( 0.002451) |
42
- +--------+-----------------------------------------------+
35
+ +--------+----------+----------+----------+----------+
36
+ | :bench | :user | :system | :total | :real |
37
+ +--------+----------+----------+----------+----------+
38
+ | :for | 0.010000 | 0.000000 | 0.010000 | 0.013039 |
39
+ | :times | 0.000000 | 0.000000 | 0.000000 | 0.003753 |
40
+ | :upto | 0.010000 | 0.000000 | 0.010000 | 0.003803 |
41
+ +--------+----------+----------+----------+----------+
43
42
  ```
44
43
 
45
44
  ## To more complex ones ...
46
45
 
47
46
  ```ruby
48
- require 'viiite'
49
- n = 15000
50
- Viiite.bm do |r|
47
+ Viiite.bench do |r|
51
48
  r.variation_point :ruby, Viiite.which_ruby
49
+ n = 15000
52
50
  r.report(:for) { for i in 1..n; a = "1"; end }
53
51
  r.report(:times) { n.times do ; a = "1"; end }
54
52
  r.report(:upto) { 1.upto(n) do ; a = "1"; end }
@@ -56,96 +54,43 @@ end
56
54
  ```
57
55
 
58
56
  ```terminal
59
- $ rvm exec viiite run bench_iteration.rb | viiite report --hierarchy --regroup=viiite,ruby
60
- +--------+--------------------------------------------------------------------+
61
- | :bench | :measure |
62
- +--------+--------------------------------------------------------------------+
63
- | :for | +----------------+-----------------------------------------------+ |
64
- | | | :ruby | :measure | |
65
- | | +----------------+-----------------------------------------------+ |
66
- | | | ruby 1.8.7 | 0.010000 0.000000 0.010000 ( 0.009677) | |
67
- | | | ruby 1.9.3dev | 0.005000 0.000000 0.005000 ( 0.005175) | |
68
- | | | jruby 1.6.3 | 0.071000 0.000000 0.071000 ( 0.071000) | |
69
- | | +----------------+-----------------------------------------------+ |
70
- | :times | +----------------+-----------------------------------------------+ |
71
- | | | :ruby | :measure | |
72
- | | +----------------+-----------------------------------------------+ |
73
- | | | ruby 1.8.7 | 0.000000 0.000000 0.000000 ( 0.003275) | |
74
- | | | ruby 1.9.3dev | 0.005000 0.000000 0.005000 ( 0.002634) | |
75
- | | | jruby 1.6.3 | 0.028000 0.000000 0.028000 ( 0.028000) | |
76
- | | +----------------+-----------------------------------------------+ |
77
- | ... | ... |
57
+ $ rvm exec viiite run bench_iteration.rb | viiite report --hierarchy --regroup=bench,ruby
58
+ +--------+-------------------------------------------------------+
59
+ | :bench | :measure |
60
+ +--------+-------------------------------------------------------+
61
+ | :for | +----------------+-------+---------+--------+-------+ |
62
+ | | | :ruby | :user | :system | :total | :real | |
63
+ | | +----------------+-------+---------+--------+-------+ |
64
+ | | | ruby 1.8.7 | 0.000 | 0.000 | 0.000 | 0.004 | |
65
+ | | | ruby 1.9.3dev | 0.010 | 0.000 | 0.010 | 0.014 | |
66
+ | | +----------------+-------+---------+--------+-------+ |
67
+ | :times | +----------------+-------+---------+--------+-------+ |
68
+ | | | :ruby | :user | :system | :total | :real | |
69
+ | | +----------------+-------+---------+--------+-------+ |
70
+ | | | ruby 1.8.7 | 0.020 | 0.000 | 0.020 | 0.018 | |
71
+ | | | ruby 1.9.3dev | 0.010 | 0.000 | 0.010 | 0.004 | |
72
+ | | +----------------+-------+---------+--------+-------+ |
73
+ | :upto | +----------------+-------+---------+--------+-------+ |
74
+ | | | :ruby | :user | :system | :total | :real | |
75
+ | | +----------------+-------+---------+--------+-------+ |
76
+ | | | ruby 1.8.7 | 0.010 | 0.000 | 0.010 | 0.004 | |
77
+ | | | ruby 1.9.3dev | 0.010 | 0.000 | 0.010 | 0.011 | |
78
+ | | +----------------+-------+---------+--------+-------+ |
79
+ +--------+-------------------------------------------------------+
78
80
  ```
79
81
 
80
82
  ## To awesomeness ...
81
83
 
82
84
  ```ruby
83
- require 'viiite'
84
- Viiite.bm do |b|
85
+ Viiite.bench do |b|
85
86
  b.variation_point :ruby, Viiite.which_ruby
86
87
  b.range_over([100, 200, 300, 400, 500], :size) do |size|
87
- b.range_over(1..5, :i) do
88
- bench_case = Array.random(size)
89
- b.report(:quicksort) { bench_case.quicksort }
90
- b.report(:bubblesort){ bench_case.bubblesort }
91
- end
88
+ bench_case = Array.new(size){ rand }
89
+ b.report(:bubblesort){ bench_case.bubblesort }
92
90
  end
93
91
  end
94
92
  ```
95
93
 
96
- ```terminal
97
- $ viiite plot bench_sort.rb -x size -y tms.total --graph=ruby --series=viiite --gnuplot | gnuplot
98
-
99
- ruby 1.8.7
100
-
101
- 0.35 ++-------+-------+--------+-------+--------+--------+-------+-------++
102
- + + + + + + bubblesort **A*** +
103
- | quicksort ##B###*A
104
- 0.3 ++ ***++
105
- | *** |
106
- 0.25 ++ ** ++
107
- | *** |
108
- | *** |
109
- 0.2 ++ *A* ++
110
- | **** |
111
- | **** |
112
- 0.15 ++ *** ++
113
- | **** |
114
- | **A* |
115
- 0.1 ++ ****** ++
116
- | ****** |
117
- 0.05 ++ ****A** ++
118
- | ******** |
119
- A**** + + + + + + +########B
120
- 0 B################B################B#################B########-------++
121
- 100 150 200 250 300 350 400 450 500
122
-
123
-
124
- ruby 1.9.3dev
125
-
126
- 0.1 ++-------+-------+--------+-------+--------+--------+-------+-------*A
127
- + + + + + + bubblesort **A*** +
128
- | quicksort **B### |
129
- | ** |
130
- 0.08 ++ *** ++
131
- | *** |
132
- | *A* |
133
- | *** |
134
- 0.06 ++ *** ++
135
- | *** |
136
- | *** |
137
- 0.04 ++ *** ++
138
- | **A* |
139
- | **** |
140
- | **** |
141
- 0.02 ++ **** ++
142
- | **A** |
143
- | ****** |
144
- + ******+ + + + + + +########B
145
- 0 A**##############B################B#################B########-------++
146
- 100 150 200 250 300 350 400 450 500
147
- ```
148
-
149
94
  ```terminal
150
95
  $ viiite plot bench_sort.rb -x size -y tms.total --graph=viiite --series=ruby --gnuplot | gnuplot
151
96
  bubblesort
@@ -171,34 +116,8 @@ $ viiite plot bench_sort.rb -x size -y tms.total --graph=viiite --series=ruby --
171
116
  A**** ########B########+ + + + + +
172
117
  0 B########+-------+--------+-------+--------+--------+-------+-------++
173
118
  100 150 200 250 300 350 400 450 500
174
-
175
-
176
- quicksort
177
-
178
- 0.012 ++-------+-------+--------+-------+--------+-------+--------+------++
179
- + + + + + + ruby 1.8.7+**A*** +
180
- | ruby 1.9.3dev ##B### |
181
- 0.01 ++ **A
182
- | ****** |
183
- | ****** |
184
- 0.008 ++ A** ++
185
- | ** |
186
- | ** |
187
- | * B
188
- 0.006 ++ ** ##+
189
- | ** ## |
190
- | ** # |
191
- 0.004 ++ * ## ++
192
- | ** ## |
193
- | ** ## |
194
- 0.002 ++ ##B##############**A######## # ++
195
- | ###### ****** ###### ## |
196
- + ######+ + ******+ + + ##+## + +
197
- 0 A****************A**------+-------+--------+-------B--------+------++
198
- 100 150 200 250 300 350 400 450 500
199
-
200
119
  ```
201
120
 
202
121
  ## On the devel side
203
122
 
204
- Fork the project on github ... and so on.
123
+ Fork the project on github ... and so on.
@@ -0,0 +1,18 @@
1
+ class Foo
2
+ attr_reader :bench_reader
3
+ def initialize
4
+ @bench_reader = @bench_method = 10
5
+ end
6
+ def bench_method
7
+ @bench_method
8
+ end
9
+ end
10
+
11
+ Viiite.bench do |b|
12
+ foo = Foo.new
13
+ b.variation_point :ruby, Viiite.which_ruby
14
+ b.range_over([1, 100_000, 1_000_000], :runs) do |runs|
15
+ b.report(:bench_reader){ runs.times{ foo.bench_reader } }
16
+ b.report(:bench_method){ runs.times{ foo.bench_method } }
17
+ end
18
+ end
@@ -1,9 +1,7 @@
1
- require 'viiite'
2
- n = 15000
3
- Viiite.bm do |r|
1
+ Viiite.bench do |r|
2
+ n = 15000
4
3
  r.variation_point :ruby, Viiite.which_ruby
5
4
  r.report(:for) { for i in 1..n; a = "1"; end }
6
5
  r.report(:times) { n.times do ; a = "1"; end }
7
6
  r.report(:upto) { 1.upto(n) do ; a = "1"; end }
8
7
  end
9
-
@@ -1,9 +1,5 @@
1
1
  class Array
2
2
 
3
- def self.random(size)
4
- Array.new(size){ Kernel.rand }
5
- end
6
-
7
3
  def quicksort(list = self)
8
4
  return list if list.nil? or list.size <= 1
9
5
  less, more = list[1..-1].partition { |i| i < list[0] }
@@ -25,14 +21,13 @@ class Array
25
21
  end
26
22
 
27
23
  require 'viiite'
28
- Viiite.bm do |b|
24
+ Viiite.bench do |b|
29
25
  b.variation_point :ruby, Viiite.which_ruby
30
26
  b.range_over([100, 200, 300, 400, 500], :size) do |size|
31
27
  b.range_over(1..5, :i) do
32
- bench_case = Array.random(size)
28
+ bench_case = Array.new(size) { rand }
33
29
  b.report(:quicksort) { bench_case.quicksort }
34
30
  b.report(:bubblesort){ bench_case.bubblesort }
35
31
  end
36
32
  end
37
33
  end
38
-
@@ -1,31 +1,35 @@
1
+ require 'fileutils'
2
+ require "delegate"
3
+
1
4
  require "viiite/version"
2
5
  require "viiite/loader"
6
+ require "viiite/errors"
3
7
  require "viiite/tms"
4
- require "viiite/formatter"
5
- require "viiite/runner"
8
+ require "viiite/benchmark"
6
9
  require "viiite/command"
7
- require "viiite/viiite_file"
8
- require "benchmark"
10
+ require "viiite/bdb"
9
11
 
10
12
  #
11
13
  # Benchmarking and complexity analyzer utility
12
14
  #
13
15
  module Viiite
14
16
 
15
- # Builds a Tms object
16
- def self.Tms(*args)
17
- Viiite::Tms.coerce(args)
18
- end
19
-
20
- def self.measure(&block)
21
- Viiite::Tms.coerce Benchmark.measure(&block)
17
+ def self.measure
18
+ t0, r0 = Process.times, Time.now
19
+ yield
20
+ t1, r1 = Process.times, Time.now
21
+ Tms.new(t1.utime - t0.utime,
22
+ t1.stime - t0.stime,
23
+ t1.cutime - t0.cutime,
24
+ t1.cstime - t0.cstime,
25
+ r1 - r0)
22
26
  end
23
27
 
24
28
  # Builds a runner instance via the DSL definition given by the block.
25
29
  #
26
30
  # Example
27
31
  #
28
- # Viiite.runner do |b|
32
+ # Viiite.bench do |b|
29
33
  # b.variation_point :ruby_version, Viiite.which_ruby
30
34
  # b.range_over([100, 1000, 10000, 100000], :runs) do |runs|
31
35
  # b.variation_point :test, :via_reader do
@@ -36,20 +40,38 @@ module Viiite
36
40
  # end
37
41
  # end
38
42
  # end
39
- #
43
+ #
44
+ def self.bench(&block)
45
+ Benchmark.new(block)
46
+ end
47
+
48
+ # Alias of Viiite.bench for compatibility
40
49
  def self.bm(&block)
41
- Runner.new(block)
50
+ warn "Viiite.bm is deprecated, use Viiite.bench instead #{caller[0]}"
51
+ bench(&block)
42
52
  end
43
53
 
44
54
  #
45
55
  # Returns a short string with a ruby interpreter description
46
- #
56
+ #
47
57
  def self.which_ruby
48
58
  if Object.const_defined?(:RUBY_DESCRIPTION)
49
- RUBY_DESCRIPTION =~ /^([^\s]+\s*[^\s]+)/
50
- $1
59
+ short_ruby_description(RUBY_DESCRIPTION)
60
+ else
61
+ "ruby #{RUBY_VERSION}"
62
+ end
63
+ end
64
+
65
+ def self.short_ruby_description(description)
66
+ case description
67
+ when /Ruby Enterprise Edition (\d{4}\.\d{2})/
68
+ "ree #{$1}"
69
+ when /^(\w+ \d\.\d\.\d) .+ patchlevel (\d+)/
70
+ "#{$1}p#{$2}"
71
+ when /^\w+ \S+/
72
+ $&
51
73
  else
52
- "ruby #{RUBY_VERSION} (#{RUBY_PLATFORM})"
74
+ raise "Unknown ruby interpreter: #{description}"
53
75
  end
54
76
  end
55
77