benchmark-timed_each 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/UNLICENSE +24 -0
  2. data/lib/benchmark/timed_each.rb +20 -0
  3. data/test.rb +20 -0
  4. metadata +72 -0
data/UNLICENSE ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org/>
@@ -0,0 +1,20 @@
1
+ require 'benchmark'
2
+
3
+ module Benchmark
4
+ def self.timed_each(collection, options={}, &block)
5
+ caption = options[:start_caption] || "Started processing collection\n"
6
+ finish_caption = options[:finish_caption] || "Finished processing collection"
7
+ label_width = nil
8
+ fmtstr = options[:format] || "- %r\n"
9
+ item_to_s = options[:item_to_s] || :to_s
10
+
11
+ benchmark(caption, label_width, fmtstr, finish_caption) do |x|
12
+ [collection.map do |item|
13
+ x.report(" processing #{item.send(item_to_s)} -") do
14
+ block.call(*item)
15
+ end
16
+ end.inject(&:+)]
17
+ end
18
+ end
19
+ end
20
+
data/test.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.setup
4
+
5
+ require 'benchmark/timed_each'
6
+
7
+ array = (97..107).to_a
8
+
9
+ hash = Hash[*array.map { |k|
10
+ [k, k.chr]
11
+ }.flatten]
12
+
13
+ Benchmark.timed_each(array) do |i|
14
+ print " doing stuff with #{i} "
15
+ sleep(0.1)
16
+ end
17
+
18
+ Benchmark.timed_each(hash, :item_to_s => :last) do |key, value|
19
+ sleep(0.1)
20
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: benchmark-timed_each
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Tim Connor
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-07 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Adds a timed_each method that accepts a collection to Benchmark. The collection is enumerated over and how long each takes is output, as well as a total.
23
+ email:
24
+ - timocratic@gmail.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - lib/benchmark/timed_each.rb
33
+ - test.rb
34
+ - UNLICENSE
35
+ has_rdoc: true
36
+ homepage: http://github.com/timocratic/benchmark-timed_each
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ hash: 3
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 23
59
+ segments:
60
+ - 1
61
+ - 3
62
+ - 6
63
+ version: 1.3.6
64
+ requirements: []
65
+
66
+ rubyforge_project: ""
67
+ rubygems_version: 1.3.7
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: A wrapper for Benchmark.benchmark that enmurates over a collection
71
+ test_files: []
72
+