yard-bench 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/README.md +83 -4
- data/lib/yard-bench/version.rb +1 -1
- data/yard-bench.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e8567b9d6ef87a15a4c3c01bd809a9bae49e42c
|
4
|
+
data.tar.gz: 79aafe9d2e453c7838c53a65b7912834d2791f21
|
5
5
|
!binary "U0hBNTEy":
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50999cac89d2fa786c7f852e858620328f7ffec57ee4e21f46e18665e79d55230f7a3ef7b6240043dfc1eda42b79842841bf9e3c7904bd6a26e2c19a5787c5e7
|
7
|
+
data.tar.gz: cc4396f9a4af167123ab2f046ecdb7b0014c4c3e71cc41faedf5ab321687f147fe6bc53da2686bc0007d4ba864c5e2129f90ccb29cdac5648b10e2f214ca135e
|
data/README.md
CHANGED
@@ -1,6 +1,81 @@
|
|
1
1
|
# YARD::Bench
|
2
2
|
|
3
|
-
|
3
|
+
Lazy benchmarking of your project, which appears in the generated [YARD](http://yardoc.org/) documentation.
|
4
|
+
There is a handy DSL provided to make benchmarking almost without additional effort.
|
5
|
+
|
6
|
+
To mark a method(s) for benchmarking, just put
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
benchmark :meth1, :meth2
|
10
|
+
```
|
11
|
+
|
12
|
+
or
|
13
|
+
|
14
|
+
⌚ :meth1, :meth2
|
15
|
+
|
16
|
+
or even
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
benchmark :⋅
|
20
|
+
```
|
21
|
+
|
22
|
+
somewhere inside your class declaration. The latter states for benchmarking all the instance methods,
|
23
|
+
defined in the class. There are four wildcards available:
|
24
|
+
|
25
|
+
* `:⋅` — benchmark instance methods of a class;
|
26
|
+
* `:⋅⋅` — benchmark instance methods of a class and all the superclasses;
|
27
|
+
* `:×` — benchmark class methods of a class;
|
28
|
+
* `:××` — benchmark class methods of a class and all the superclasses;
|
29
|
+
|
30
|
+
Let’s say there is a class `BmExample` that you want to benchmark:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
# Example module to test benchmarking functionality.
|
34
|
+
module BmExamples
|
35
|
+
# Example class to test benchmarking functionality.
|
36
|
+
class BmExample
|
37
|
+
benchmark :do_it
|
38
|
+
⌚ :do_other
|
39
|
+
|
40
|
+
# The value
|
41
|
+
attr_reader :value
|
42
|
+
# Constructor.
|
43
|
+
# @param value [Fixnum] the value to add to 10 within {#value} initializer.
|
44
|
+
# @param addval [Fixnum] another value to add to 10 within {#value} initializer.
|
45
|
+
# @param attrs [Hash] additional parameters (ignored.)
|
46
|
+
def initialize value, addval, *attrs
|
47
|
+
@value = 10 + value + addval
|
48
|
+
end
|
49
|
+
# Multiplies {#value} by parameter given.
|
50
|
+
# @param deg [Fixnum]
|
51
|
+
# @return [Fixnum] {#value} multiplied by deg.
|
52
|
+
def do_it deg
|
53
|
+
@value * deg
|
54
|
+
end
|
55
|
+
# Produces a power of the parameter given.
|
56
|
+
# @param base [Fixnum]
|
57
|
+
# @return [Fixnum] {#value} in a power of base
|
58
|
+
def do_other base = 2
|
59
|
+
@value ** base
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
The fifth and sixth lines of code will mark methods `do_it` and `do_other` for benchmarking.
|
66
|
+
Actual benchmarking will take place during yard documentation production. This definitely will
|
67
|
+
slow up the documentation generation, but in the production environment these do not
|
68
|
+
interfere the normal execution timeline at all.
|
69
|
+
|
70
|
+
After the generation is done, the methods are measured with an intellectual algorhytm:
|
71
|
+
|
72
|
+

|
73
|
+
|
74
|
+
The results are 〈almost〉 independent of the architecture of the target machine on which
|
75
|
+
the measurements were done (they are normalized by `1_000_000.times {"foo bar baz".capitalize}`.)
|
76
|
+
There are meaningful values for amounts of times to test chosen (three results, having
|
77
|
+
significant figures in hundredth part.) The algorythm calculates the deviation of results and
|
78
|
+
suggests `O(N)` power of function timing, whether possible.
|
4
79
|
|
5
80
|
## Installation
|
6
81
|
|
@@ -20,12 +95,16 @@ Or install it yourself as:
|
|
20
95
|
|
21
96
|
Put the following code anywhere within your class:
|
22
97
|
|
23
|
-
|
98
|
+
```ruby
|
99
|
+
benchmark :func1, :func2
|
100
|
+
```
|
24
101
|
|
25
102
|
or even:
|
26
103
|
|
27
|
-
|
28
|
-
|
104
|
+
```ruby
|
105
|
+
class String
|
106
|
+
⌚ :⋅
|
107
|
+
```
|
29
108
|
|
30
109
|
and the benchmarks for the chosen functions will be included in yardoc.
|
31
110
|
|
data/lib/yard-bench/version.rb
CHANGED
data/yard-bench.gemspec
CHANGED