pry-measure 0.0.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fd7ecb4b9be0aa50ba6a782798a7e3ff54f817ef
4
+ data.tar.gz: 2b502507be3cf9d891545f7bdf091d4846467d87
5
+ SHA512:
6
+ metadata.gz: 8605ad7da9656de67b56754d7941359ce38046b7e779f6f4a6c71919f13c1881d7b7686e5c2c40adc7be050dd6cccdd9c9f60a9666273eb8784a0da42cbbd5f5
7
+ data.tar.gz: 1a97ada99ecb026394c4a9128b795acf467d265b66651cdd069030d0477adc6151f4e502adf4637adc3df6dafd214f25be2415887e07e377498c813f7fc62233
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Matt Dodds
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # pry-measure
2
+
3
+ Adds `pry-measure` command for quick adhoc benchmarking.
4
+
5
+
6
+ ## Installation
7
+
8
+ ```ruby
9
+ gem install pry-measure
10
+ ```
11
+
12
+ or added to the Gemfile:
13
+ ```ruby
14
+ gem 'pry-measure'
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```bash
20
+ pry-measure -t 10 #{`curl http://google.com`}
21
+ ```
22
+
23
+ The above passes the interpolated code to [Benchmark.measure](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/benchmark/rdoc/Benchmark.html#method-c-measure) to be evaluated 10 times. Upon completion the command returns a results hash with the average times:
24
+
25
+ ```ruby
26
+ => {
27
+ :real => 0.1958,
28
+ :utime => 0.0,
29
+ :stime => 0.002,
30
+ :total => 0.056
31
+ }
32
+ ```
33
+
34
+ ```bash
35
+ pry-realtime #{`curl http://google.com`}
36
+ => 0.6405
37
+ ```
38
+
39
+
@@ -0,0 +1,12 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'pry'
4
+
5
+ module PryMeasure
6
+ Commands = Pry::CommandSet.new
7
+ end
8
+
9
+ require "pry-measure/measure_command"
10
+ require "pry-measure/realtime_command"
11
+
12
+ Pry.commands.import PryMeasure::Commands
@@ -0,0 +1,32 @@
1
+ module PryMeasure
2
+ class Marker
3
+ def self.measure(execution_times, arg_string, command, realtime=false, show_output=false, results=[])
4
+ execution_times.times do
5
+ results << Benchmark.measure do
6
+ begin
7
+ command.interpolate_string arg_string
8
+ rescue Pry::RescuableException => ex
9
+ raise Pry::CommandError, ex
10
+ end
11
+ end
12
+ end
13
+
14
+ if show_output == true
15
+ unless realtime
16
+ puts " user system total real"
17
+ end
18
+ puts results
19
+ end
20
+
21
+ average = average_results(results, execution_times)
22
+ realtime ? average[:real] : average
23
+ end
24
+
25
+ def self.average_results(results, execution_times, response={})
26
+ [:real, :utime, :stime, :total].each do |key|
27
+ response.merge!(key =>(results.map(&key).inject(&:+) / execution_times.to_i).round(4))
28
+ end
29
+ response
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,41 @@
1
+ require "pry-measure/marker"
2
+
3
+ PryMeasure::Commands.create_command "pry-measure" do
4
+ description "Measure a block of code using Ruby's benchmark module"
5
+
6
+ banner <<-BANNER
7
+ Usage: measure [ -t <times> -s ] <block>
8
+
9
+ Calls the block for the given amount of times (default 500) and returns benchmark results.
10
+ BANNER
11
+
12
+ command_options(
13
+ shellwords: false,
14
+ keep_retval: true,
15
+ interpolate: false
16
+ )
17
+
18
+ def setup
19
+ @times = 500
20
+ end
21
+
22
+ def options(opt)
23
+ opt.on :s, :show, "Shows default benchmark output"
24
+ opt.on :t, :times, "Times to call block (default: 500)", optional: true, argument: true
25
+ end
26
+
27
+ def process
28
+ if opts[:times]
29
+ @times = opts[:times]
30
+ raise Pry::CommandError, "-t should be an integer" unless times_is_int?
31
+ end
32
+
33
+ output = !opts[:show].nil?
34
+
35
+ PryMeasure::Marker.measure @times.to_i, arg_string, self, false, output
36
+ end
37
+
38
+ def times_is_int?
39
+ !!(@times =~ /^[-+]?[0-9]+$/)
40
+ end
41
+ end
@@ -0,0 +1,21 @@
1
+ require "pry-measure/marker"
2
+
3
+ PryMeasure::Commands.create_command "pry-realtime" do
4
+ description "Measure the execution time of code using Ruby's Benchmark.realtime"
5
+
6
+ banner <<-BANNER
7
+ Usage: pry-realtime <code>
8
+
9
+ Evaluates code using Benchmark.realtime
10
+ BANNER
11
+
12
+ command_options(
13
+ shellwords: false,
14
+ keep_retval: true,
15
+ interpolate: false
16
+ )
17
+
18
+ def process
19
+ PryMeasure::Marker.measure 1, arg_string, self, true
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module PryMeasure
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pry-measure
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Dodds
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.10
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.10
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - matthewrusselldodds@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/pry-measure/marker.rb
63
+ - lib/pry-measure/measure_command.rb
64
+ - lib/pry-measure/realtime_command.rb
65
+ - lib/pry-measure/version.rb
66
+ - lib/pry-measure.rb
67
+ - LICENSE
68
+ - README.md
69
+ homepage: http://github.com/matthewrdodds/pry-measure
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: 1.3.6
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.0.3
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Adds simple benchmark tool to pry
93
+ test_files: []