clocker 0.1.5 → 0.1.6
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/Gemfile.lock +2 -2
- data/README.md +67 -11
- data/bin/clocker +62 -0
- data/lib/clocker.rb +19 -15
- data/lib/clocker/version.rb +5 -2
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e356e7d0d50521af9d67ef4698607fa341f746c3
|
|
4
|
+
data.tar.gz: 48f595a7020894dc8f649a3085d098ed96be1475
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2408d28b66ba3c6261f7ecdc7e4f900dc9457b153aad468282474a2ca230863f3987d5d4390aee3fec8f7a4473a6e28c7b4efd96ee83038b8b055245deee9080
|
|
7
|
+
data.tar.gz: af3169ae0ab1ff937dcac51d4f3468b413a269896b19b6cac2e1dcc829c7090e6fda147560ac6cbd668bd45b92532eee38a8eb29c9a80821dd6ed476e8bf206a
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -1,9 +1,37 @@
|
|
|
1
1
|
# Clocker
|
|
2
|
+
Quick way to find out how long that command or block of code takes to run.
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
## Usage
|
|
5
|
+
### Command Line
|
|
6
|
+
Simply run `clocker` followed by a command or block in double quotes. Add an `-m` before the command or block to print out start and end times.
|
|
7
|
+
|
|
8
|
+
Ex. 1
|
|
9
|
+
```
|
|
10
|
+
$ clocker "puts 'hi'"
|
|
11
|
+
hi
|
|
12
|
+
Clocked at 0 mins, 0 secs, 0 ms
|
|
13
|
+
```
|
|
4
14
|
|
|
5
|
-
|
|
15
|
+
Ex. 2
|
|
16
|
+
```
|
|
17
|
+
$ clocker "2.times { puts 'hello world'; sleep(0.6) }"
|
|
18
|
+
hello world
|
|
19
|
+
hello world
|
|
20
|
+
|
|
21
|
+
Clocked at 0 mins, 1 secs, and 210 ms
|
|
22
|
+
```
|
|
6
23
|
|
|
24
|
+
Ex. 3
|
|
25
|
+
```
|
|
26
|
+
$ clocker -m "1.upto(5) { |i| print i+1; sleep(0.4) }"
|
|
27
|
+
start: 2015-08-18 16:16:47 -0700
|
|
28
|
+
23456
|
|
29
|
+
ended: 2015-08-18 16:16:49 -0700
|
|
30
|
+
|
|
31
|
+
Clocked at 0 mins, 2 secs, and 12 ms
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### As Gem Library
|
|
7
35
|
Add this line to your application's Gemfile:
|
|
8
36
|
|
|
9
37
|
```ruby
|
|
@@ -11,18 +39,46 @@ gem 'clocker'
|
|
|
11
39
|
```
|
|
12
40
|
|
|
13
41
|
And then execute:
|
|
14
|
-
|
|
15
|
-
|
|
42
|
+
```
|
|
43
|
+
$ bundle
|
|
44
|
+
```
|
|
16
45
|
|
|
17
46
|
Or install it yourself as:
|
|
47
|
+
```
|
|
48
|
+
$ gem install clocker
|
|
49
|
+
```
|
|
18
50
|
|
|
19
|
-
|
|
51
|
+
Sample code block:
|
|
52
|
+
```ruby
|
|
53
|
+
>> clocker = Clocker.new
|
|
54
|
+
>> clocker.clock do
|
|
55
|
+
>> # code here
|
|
56
|
+
>> end
|
|
57
|
+
```
|
|
20
58
|
|
|
21
|
-
|
|
59
|
+
By default, clocker will not print out the start time before the command|block, or the end time after the command|block, unless you pass the instance `show_messages: true`.
|
|
60
|
+
|
|
61
|
+
```ruby
|
|
62
|
+
>> c1 = Clocker.new
|
|
63
|
+
>> duration = c1.clock do
|
|
64
|
+
>> 3.times { print 'c1'; sleep(1) }
|
|
65
|
+
>> end
|
|
66
|
+
>> puts
|
|
67
|
+
>> puts duration
|
|
68
|
+
|
|
69
|
+
c1c1c1
|
|
70
|
+
{:mins=>0, :secs=>3, :ms=>13}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```ruby
|
|
74
|
+
>> c2 = Clocker.new(show_messages: true)
|
|
75
|
+
>> duration = c2.clock do
|
|
76
|
+
>> 3.times { purint 'c2'; sleep(1) }
|
|
77
|
+
>> end
|
|
78
|
+
>> puts duration
|
|
22
79
|
|
|
80
|
+
start: 2015-08-18 16:07:17 -0700
|
|
81
|
+
c2c2c2
|
|
82
|
+
ended: 2015-08-18 16:07:20 -0700
|
|
83
|
+
{:mins=>0, :secs=>3, :ms=>14}
|
|
23
84
|
```
|
|
24
|
-
clocker = Clocker.new
|
|
25
|
-
clocker.clock do
|
|
26
|
-
# code here
|
|
27
|
-
end
|
|
28
|
-
```
|
data/bin/clocker
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'optparse'
|
|
4
|
+
|
|
5
|
+
require_relative '../lib/clocker'
|
|
6
|
+
require_relative '../lib/clocker/version'
|
|
7
|
+
|
|
8
|
+
BINARY_NAME = $PROGRAM_NAME.split('/').last
|
|
9
|
+
|
|
10
|
+
def parse_options
|
|
11
|
+
options = {
|
|
12
|
+
show_messages: false
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
optparse = OptionParser.new do |opts|
|
|
16
|
+
opts.banner = "usage: #{BINARY_NAME} [command|block]"
|
|
17
|
+
|
|
18
|
+
opts.on('-m', '--message', 'Show start and ended messages') do |m|
|
|
19
|
+
options[:show_messages] = m
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
opts.on('-v', '--version', 'Display version number and exit') do
|
|
23
|
+
puts "#{BINARY_NAME} #{Clocker::VERSION}"
|
|
24
|
+
exit
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
opts.on('-h', '--help', 'Display this screen and exit') do
|
|
28
|
+
puts opts
|
|
29
|
+
exit
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
optparse.parse!()
|
|
34
|
+
|
|
35
|
+
return options
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def print_error(error)
|
|
39
|
+
case error
|
|
40
|
+
when OptionParser::InvalidOption
|
|
41
|
+
puts "#{BINARY_NAME}: illegal option #{error.args.join(' ')}"
|
|
42
|
+
else
|
|
43
|
+
puts "An unexpected error occurred while running #{BINARY_NAME}:"
|
|
44
|
+
puts " #{error}\n"
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
begin
|
|
49
|
+
options = parse_options
|
|
50
|
+
|
|
51
|
+
if (ARGV.count > 0)
|
|
52
|
+
c = Clocker.new(options)
|
|
53
|
+
t = c.clock { eval(ARGV[0]) }
|
|
54
|
+
puts
|
|
55
|
+
puts "Clocked at #{t[:mins]} mins, #{t[:secs]} secs, and #{t[:ms]} ms"
|
|
56
|
+
else
|
|
57
|
+
puts "#{BINARY_NAME} error: missing command or block"
|
|
58
|
+
end
|
|
59
|
+
rescue => error
|
|
60
|
+
print_error(error)
|
|
61
|
+
exit(false)
|
|
62
|
+
end
|
data/lib/clocker.rb
CHANGED
|
@@ -11,27 +11,31 @@ class Clocker
|
|
|
11
11
|
self.options = options
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
def clock
|
|
14
|
+
def clock(&block)
|
|
15
15
|
@start = Time.now
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
|
|
17
|
+
if options[:show_messages]
|
|
18
|
+
puts "\nstart: #{@start}"
|
|
18
19
|
end
|
|
19
|
-
|
|
20
|
+
|
|
20
21
|
begin
|
|
21
|
-
|
|
22
|
+
block.call
|
|
22
23
|
rescue StandardError => e
|
|
23
24
|
puts e.message
|
|
24
25
|
end
|
|
25
|
-
|
|
26
|
+
|
|
27
|
+
return stop
|
|
26
28
|
end
|
|
27
|
-
|
|
29
|
+
|
|
28
30
|
def stop
|
|
29
31
|
@stop = Time.now
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
|
|
33
|
+
if options[:show_messages]
|
|
34
|
+
puts "\nended: #{@stop}"
|
|
32
35
|
end
|
|
36
|
+
|
|
33
37
|
ms = ((@stop - @start) * 1000).to_i
|
|
34
|
-
|
|
38
|
+
|
|
35
39
|
if ms > 60000
|
|
36
40
|
mins = ms / 60000
|
|
37
41
|
ms = ms - (60000 * mins)
|
|
@@ -39,15 +43,15 @@ class Clocker
|
|
|
39
43
|
secs = ms / 1000
|
|
40
44
|
ms = ms % 1000
|
|
41
45
|
end
|
|
42
|
-
|
|
43
|
-
{ mins: mins, secs: secs, ms: ms }
|
|
46
|
+
|
|
47
|
+
return { mins: mins, secs: secs, ms: ms }
|
|
44
48
|
elsif ms > 1000
|
|
45
49
|
secs = ms / 1000
|
|
46
50
|
ms = ms % 1000
|
|
47
|
-
|
|
48
|
-
{ mins: 0, secs: secs, ms: ms }
|
|
51
|
+
|
|
52
|
+
return { mins: 0, secs: secs, ms: ms }
|
|
49
53
|
else
|
|
50
|
-
{ mins: 0, secs: 0, ms: ms }
|
|
54
|
+
return { mins: 0, secs: 0, ms: ms }
|
|
51
55
|
end
|
|
52
56
|
end
|
|
53
57
|
end
|
data/lib/clocker/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: clocker
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michael Chadwick
|
|
@@ -42,7 +42,8 @@ description: Give Clocker some code to process, and it will run it and display h
|
|
|
42
42
|
long it took to finish.
|
|
43
43
|
email:
|
|
44
44
|
- mike@codana.me
|
|
45
|
-
executables:
|
|
45
|
+
executables:
|
|
46
|
+
- clocker
|
|
46
47
|
extensions: []
|
|
47
48
|
extra_rdoc_files: []
|
|
48
49
|
files:
|
|
@@ -54,6 +55,7 @@ files:
|
|
|
54
55
|
- LICENSE.txt
|
|
55
56
|
- README.md
|
|
56
57
|
- Rakefile
|
|
58
|
+
- bin/clocker
|
|
57
59
|
- clocker.gemspec
|
|
58
60
|
- lib/clocker.rb
|
|
59
61
|
- lib/clocker/version.rb
|