benchmark-timed_each 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +52 -0
- data/lib/benchmark/timed_each.rb +9 -0
- metadata +5 -4
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
Install
|
2
|
+
-------
|
3
|
+
gem install benchmark-timed_each
|
4
|
+
Use
|
5
|
+
---
|
6
|
+
require 'benchmark/timed_each'
|
7
|
+
|
8
|
+
### Simplest case - an array of items
|
9
|
+
array = (97..107).to_a
|
10
|
+
Benchmark.timed_each(array) do |i|
|
11
|
+
print " doing stuff with #{i} "
|
12
|
+
sleep(0.1)
|
13
|
+
end
|
14
|
+
|
15
|
+
>Started processing collection
|
16
|
+
> processing 97 - doing stuff with 97 - (0.100251)
|
17
|
+
> processing 98 - doing stuff with 98 - (0.100237)
|
18
|
+
> processing 99 - doing stuff with 99 - (0.100298)
|
19
|
+
> processing 100 - doing stuff with 100 - (0.100258)
|
20
|
+
> processing 101 - doing stuff with 101 - (0.100192)
|
21
|
+
> processing 102 - doing stuff with 102 - (0.100307)
|
22
|
+
> processing 103 - doing stuff with 103 - (0.100200)
|
23
|
+
> processing 104 - doing stuff with 104 - (0.100105)
|
24
|
+
> processing 105 - doing stuff with 105 - (0.100162)
|
25
|
+
> processing 106 - doing stuff with 106 - (0.100247)
|
26
|
+
> processing 107 - doing stuff with 107 - (0.100291)
|
27
|
+
>Finished processing collection- (1.102548)
|
28
|
+
|
29
|
+
### Hashes or other things passing multiple values to block
|
30
|
+
hash = Hash[*array.map { |k|
|
31
|
+
[k, k.chr]
|
32
|
+
}.flatten]
|
33
|
+
Benchmark.timed_each(hash, :item_to_s => :last) do |key, value|
|
34
|
+
sleep(0.1)
|
35
|
+
end
|
36
|
+
|
37
|
+
>Started processing collection
|
38
|
+
> processing h -- (0.100102)
|
39
|
+
> processing c -- (0.100158)
|
40
|
+
> processing i -- (0.100150)
|
41
|
+
> processing d -- (0.100228)
|
42
|
+
> processing j -- (0.100162)
|
43
|
+
> processing e -- (0.100283)
|
44
|
+
> processing k -- (0.100260)
|
45
|
+
> processing f -- (0.100133)
|
46
|
+
> processing a -- (0.100212)
|
47
|
+
> processing g -- (0.100249)
|
48
|
+
> processing b -- (0.100139)
|
49
|
+
>Finished processing collection- (1.102076)
|
50
|
+
|
51
|
+
### Options
|
52
|
+
:start\_caption, :finish\_caption, :format, :item\_to\_s
|
data/lib/benchmark/timed_each.rb
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
require 'benchmark'
|
2
2
|
|
3
3
|
module Benchmark
|
4
|
+
# Iterate over the passed in collection, outputing benchmark info at each step
|
5
|
+
#
|
6
|
+
# @param [Enumerable] collection the collection to iterate over
|
7
|
+
# @param [Hash] options the collection to iterate over
|
8
|
+
# @option options [String] :start_caption ("Started processing collection\n") Output before starting
|
9
|
+
# @option options [String] :finish_caption ("Finished processing collection") Output when finished, on same line as total time
|
10
|
+
# @option options [String] :format ("- %r\n") Format String for benchmark (fmtstr)
|
11
|
+
# @option options [Symbol, String] :item_to_s (:to_s) Output before starting
|
12
|
+
|
4
13
|
def self.timed_each(collection, options={}, &block)
|
5
14
|
caption = options[:start_caption] || "Started processing collection\n"
|
6
15
|
finish_caption = options[:finish_caption] || "Finished processing collection"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: benchmark-timed_each
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tim Connor
|
@@ -32,6 +32,7 @@ files:
|
|
32
32
|
- lib/benchmark/timed_each.rb
|
33
33
|
- test.rb
|
34
34
|
- UNLICENSE
|
35
|
+
- README.md
|
35
36
|
has_rdoc: true
|
36
37
|
homepage: http://github.com/timocratic/benchmark-timed_each
|
37
38
|
licenses: []
|
@@ -63,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
64
|
version: 1.3.6
|
64
65
|
requirements: []
|
65
66
|
|
66
|
-
rubyforge_project:
|
67
|
+
rubyforge_project:
|
67
68
|
rubygems_version: 1.3.7
|
68
69
|
signing_key:
|
69
70
|
specification_version: 3
|