hop_timer 0.0.1
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 +7 -0
- data/.gitignore +10 -0
- data/.rubocop.yml +41 -0
- data/.rubocop_todo.yml +91 -0
- data/.travis.yml +16 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +94 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/hop_timer.gemspec +35 -0
- data/lib/hop_timer.rb +172 -0
- data/lib/hop_timer/version.rb +3 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c4beec7c726bc7c516cbf6f25978855f32399d7ba879c64d245b87f804694a49
|
4
|
+
data.tar.gz: b894a0d0620f99b73c78e3882f3b8313710bcab3f59dc76f08520beb704e6a0a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 680395a4a60eeea6f1d86a033c64c6b8b9ab4200efd1e17e159e8a755de08236b600a83828f0911464264ec144fab92fe6e60c56e498a3f078de099a0e34aae5
|
7
|
+
data.tar.gz: bd5fb0f816f495a6dfc1cdb81d49e493be2c94dbd3e770864b64f01623754f3b86495e985b34982441aa0491878fe6669bae4e5b0705ae543c5a1be78923bf07
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
Style/InlineComment:
|
4
|
+
Description: Avoid inline comments.
|
5
|
+
Enabled: true
|
6
|
+
|
7
|
+
Style/MutableConstant:
|
8
|
+
Description: Freeze mutable constants.
|
9
|
+
Enabled: true
|
10
|
+
|
11
|
+
Style/TrailingWhitespace:
|
12
|
+
Enabled: true
|
13
|
+
|
14
|
+
Style/Documentation:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Metrics/AbcSize:
|
18
|
+
Description: >-
|
19
|
+
A calculated magnitude based on number of assignments,
|
20
|
+
branches, and conditions.
|
21
|
+
Enabled: true
|
22
|
+
Max: 40
|
23
|
+
|
24
|
+
Metrics/MethodLength:
|
25
|
+
Enabled: true
|
26
|
+
Max: 12
|
27
|
+
|
28
|
+
Style/HashSyntax:
|
29
|
+
Description: >-
|
30
|
+
Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax
|
31
|
+
{ :a => 1, :b => 2 }.
|
32
|
+
Enabled: true
|
33
|
+
EnforcedStyle: ruby19_no_mixed_keys
|
34
|
+
UseHashRocketsWithSymbolValues: false
|
35
|
+
PreferHashRocketsForNonAlnumEndingSymbols: false
|
36
|
+
|
37
|
+
Metrics/MethodLength:
|
38
|
+
Description: 'Avoid methods longer than 24 lines of code.'
|
39
|
+
Enabled: true
|
40
|
+
CountComments: false # count full line comments?
|
41
|
+
Max: 24
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2020-08-23 19:40:38 +0100 using RuboCop version 0.85.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 2
|
10
|
+
# Cop supports --auto-correct.
|
11
|
+
# Configuration parameters: TreatCommentsAsGroupSeparators, Include.
|
12
|
+
# Include: **/*.gemspec
|
13
|
+
Gemspec/OrderedDependencies:
|
14
|
+
Exclude:
|
15
|
+
- 'hop_timer.gemspec'
|
16
|
+
|
17
|
+
# Offense count: 1
|
18
|
+
# Cop supports --auto-correct.
|
19
|
+
# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
|
20
|
+
Layout/ExtraSpacing:
|
21
|
+
Exclude:
|
22
|
+
- 'hop_timer.gemspec'
|
23
|
+
|
24
|
+
# Offense count: 1
|
25
|
+
# Cop supports --auto-correct.
|
26
|
+
# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator.
|
27
|
+
# SupportedStylesForExponentOperator: space, no_space
|
28
|
+
Layout/SpaceAroundOperators:
|
29
|
+
Exclude:
|
30
|
+
- 'hop_timer.gemspec'
|
31
|
+
|
32
|
+
# Offense count: 2
|
33
|
+
# Cop supports --auto-correct.
|
34
|
+
# Configuration parameters: EnforcedStyle.
|
35
|
+
# SupportedStyles: final_newline, final_blank_line
|
36
|
+
Layout/TrailingEmptyLines:
|
37
|
+
Exclude:
|
38
|
+
- 'Gemfile'
|
39
|
+
- 'Rakefile'
|
40
|
+
|
41
|
+
# Offense count: 3
|
42
|
+
# Cop supports --auto-correct.
|
43
|
+
# Configuration parameters: EnforcedStyle.
|
44
|
+
# SupportedStyles: compact, expanded
|
45
|
+
Style/EmptyMethod:
|
46
|
+
Exclude:
|
47
|
+
- 'test/hop_timer_test.rb'
|
48
|
+
|
49
|
+
# Offense count: 2
|
50
|
+
# Cop supports --auto-correct.
|
51
|
+
Style/ExpandPathArguments:
|
52
|
+
Exclude:
|
53
|
+
- 'hop_timer.gemspec'
|
54
|
+
|
55
|
+
# Offense count: 8
|
56
|
+
# Cop supports --auto-correct.
|
57
|
+
# Configuration parameters: EnforcedStyle.
|
58
|
+
# SupportedStyles: always, always_true, never
|
59
|
+
Style/FrozenStringLiteralComment:
|
60
|
+
Exclude:
|
61
|
+
- 'Gemfile'
|
62
|
+
- 'Rakefile'
|
63
|
+
- 'bin/console'
|
64
|
+
- 'hop_timer.gemspec'
|
65
|
+
- 'lib/hop_timer.rb'
|
66
|
+
- 'lib/hop_timer/version.rb'
|
67
|
+
- 'test/hop_timer_test.rb'
|
68
|
+
- 'test/test_helper.rb'
|
69
|
+
|
70
|
+
# Offense count: 1
|
71
|
+
# Cop supports --auto-correct.
|
72
|
+
# Configuration parameters: EnforcedStyle.
|
73
|
+
# SupportedStyles: literals, strict
|
74
|
+
Style/MutableConstant:
|
75
|
+
Exclude:
|
76
|
+
- 'lib/hop_timer/version.rb'
|
77
|
+
|
78
|
+
# Offense count: 57
|
79
|
+
# Cop supports --auto-correct.
|
80
|
+
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
|
81
|
+
# SupportedStyles: single_quotes, double_quotes
|
82
|
+
Style/StringLiterals:
|
83
|
+
Exclude:
|
84
|
+
- 'Gemfile'
|
85
|
+
- 'Rakefile'
|
86
|
+
- 'bin/console'
|
87
|
+
- 'hop_timer.gemspec'
|
88
|
+
- 'lib/hop_timer.rb'
|
89
|
+
- 'lib/hop_timer/version.rb'
|
90
|
+
- 'test/hop_timer_test.rb'
|
91
|
+
- 'test/test_helper.rb'
|
data/.travis.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
---
|
2
|
+
language: ruby
|
3
|
+
cache: bundler
|
4
|
+
rvm:
|
5
|
+
- 2.6.5
|
6
|
+
|
7
|
+
script: 'bundle exec rake'
|
8
|
+
|
9
|
+
notifications:
|
10
|
+
email:
|
11
|
+
recipients:
|
12
|
+
sunguralican@gmail.com
|
13
|
+
on_failure: change
|
14
|
+
on_success: never
|
15
|
+
|
16
|
+
before_install: gem install bundler -v 2.1.4
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 asungur
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# HopTimer
|
2
|
+
[](https://travis-ci.com/asungur/hop_timer)
|
3
|
+
[](https://badge.fury.io/rb/hop_timer)
|
4
|
+

|
5
|
+
|
6
|
+
HopTimer is a user friendly benchmarking gem that works as a wrapper for Ruby's default benchmark utility. If you are frequently using benchmark and looking for a more intuitive solution or even planning to start benchmarking in general, HopTimer is for you.
|
7
|
+
|
8
|
+
HopTimer uses **check points** and evaluates the runtime between two. As you develop your application define instances of check points and evaluate them whenever you want.
|
9
|
+
|
10
|
+
## **Installation**
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'hop_timer'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
$ bundle install
|
22
|
+
```
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
$ gem install hop_timer
|
28
|
+
```
|
29
|
+
|
30
|
+
## **Usage**
|
31
|
+
|
32
|
+
Once **HopTimer** is installed on your machine, `require` the gem.
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
require 'hop_timer'
|
36
|
+
```
|
37
|
+
|
38
|
+
`HopTimer.eval` calculates the runtime between the instances of `HopTimer::CheckPoint` . It logs a table to the console and provides the same values in a form of hash.
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
flag1 = HopTimer::CheckPoint.new('flag1')
|
42
|
+
|
43
|
+
sleep 1.2 # OPERATIONS THAT YOU WANT TO BENCHMARK HERE
|
44
|
+
|
45
|
+
flag2 = HopTimer::CheckPoint.new('flag2')
|
46
|
+
|
47
|
+
HopTimer.eval(flag1, flag2)
|
48
|
+
# RETURNS =>
|
49
|
+
{"user"=>"0.000022",
|
50
|
+
"system"=>"0.000045",
|
51
|
+
"total"=>"0.000067",
|
52
|
+
"real"=>"1.201469"}
|
53
|
+
|
54
|
+
# LOGS TO THE CONSOLE =>
|
55
|
+
=============Runtime between flag1 and flag2=============
|
56
|
+
┌-------------┬-------------┬-------------┬-------------┐
|
57
|
+
| user | system | total | real |
|
58
|
+
├-------------┼-------------┼-------------┼-------------┤
|
59
|
+
| 0.000022 | 0.000045 | 0.000067 | 1.201469(s) |
|
60
|
+
└-------------┴-------------┴-------------┴-------------┘
|
61
|
+
```
|
62
|
+
|
63
|
+
The table breakdowns the runtime as [CPU time](https://en.wikipedia.org/wiki/CPU_time)(user time, system time) and [real time](https://ruby-doc.org/core-2.6.3/Time.html) in seconds. HopTimer uses [Process](https://ruby-doc.org/core-2.6.1/Process.html) and [Benchmark::Tms](https://ruby-doc.org/stdlib-2.4.0/libdoc/benchmark/rdoc/Benchmark/Tms.html) for the calculation.
|
64
|
+
|
65
|
+
The values provided with the returned hash can be specified as floats or strings(default).
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
HopTimer.eval(flag1, flag2, :string)
|
69
|
+
{"user"=>"0.000022",
|
70
|
+
"system"=>"0.000045",
|
71
|
+
"total"=>"0.000067",
|
72
|
+
"real"=>"1.201469"}
|
73
|
+
|
74
|
+
HopTimer.eval(flag1, flag2, :float) # OR
|
75
|
+
HopTimer.eval(flag1, flag2, :number)
|
76
|
+
{"user"=>3.9e-11,
|
77
|
+
"system"=>2.5e-11,
|
78
|
+
"total"=>6.4e-11,
|
79
|
+
"real"=>1.201488e-06}
|
80
|
+
```
|
81
|
+
|
82
|
+
## **Development**
|
83
|
+
|
84
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
85
|
+
|
86
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org/).
|
87
|
+
|
88
|
+
## Contributing
|
89
|
+
|
90
|
+
Bug reports and pull requests are welcome on GitHub at [https://github.com/asungur/hop_timer](https://github.com/%5BUSERNAME%5D/hop_timer).
|
91
|
+
|
92
|
+
## License
|
93
|
+
|
94
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "hop_timer"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/hop_timer.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'hop_timer/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "hop_timer"
|
7
|
+
spec.version = HopTimer::VERSION
|
8
|
+
spec.authors = ["Alican Sungur"]
|
9
|
+
spec.email = ["sunguralican@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "A tool that measures runtime between checkpoints"
|
12
|
+
spec.description = "A ruby gem that calculates runtime between user defined checkpoints."
|
13
|
+
spec.homepage = "https://github.com/asungur/hop_timer"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
30
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
31
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
32
|
+
spec.add_development_dependency "rspec"
|
33
|
+
spec.add_development_dependency "minitest-reporters"
|
34
|
+
spec.add_development_dependency 'coveralls'
|
35
|
+
end
|
data/lib/hop_timer.rb
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
require "hop_timer/version"
|
2
|
+
require 'benchmark'
|
3
|
+
|
4
|
+
module HopTimer
|
5
|
+
TITLES = "user system total real".split(' ').freeze
|
6
|
+
TIME_VALUES = %i[string number float].freeze
|
7
|
+
TABLE_ELEMENTS = {
|
8
|
+
top_center: "┬",
|
9
|
+
top_right: "┐",
|
10
|
+
mid_center: "┼",
|
11
|
+
mid_right: "┤",
|
12
|
+
bot_center: "┴",
|
13
|
+
bot_right: "┘",
|
14
|
+
|
15
|
+
top_divider: '┌',
|
16
|
+
top_row: "|",
|
17
|
+
mid_divider: "├",
|
18
|
+
bot_row: "|",
|
19
|
+
bot_divider: "└"
|
20
|
+
}.freeze
|
21
|
+
|
22
|
+
class CheckPoint
|
23
|
+
attr_reader :name, :r_time, :u_time, :s_time, :cu_time, :cs_time
|
24
|
+
|
25
|
+
def initialize(name)
|
26
|
+
name_validation(name)
|
27
|
+
|
28
|
+
@name = name
|
29
|
+
p_times = Process.times
|
30
|
+
@r_time = Time.now
|
31
|
+
@u_time = p_times.utime
|
32
|
+
@s_time = p_times.stime
|
33
|
+
@cu_time = p_times.cutime
|
34
|
+
@cs_time = p_times.cstime
|
35
|
+
end
|
36
|
+
|
37
|
+
def -(other)
|
38
|
+
time_diff_set = {}
|
39
|
+
|
40
|
+
time_diff_set[:r_diff] = r_time - other.r_time
|
41
|
+
time_diff_set[:u_diff] = u_time - other.u_time
|
42
|
+
time_diff_set[:s_diff] = s_time - other.s_time
|
43
|
+
time_diff_set[:cu_diff] = cu_time - other.cu_time
|
44
|
+
time_diff_set[:cs_diff] = cs_time - other.cs_time
|
45
|
+
|
46
|
+
time_diff_set.each { |key, val| time_diff_set[key] = val.abs }
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def name_validation(name)
|
52
|
+
error_message = "Use alphanumeric and underscore characters only"
|
53
|
+
invalid_name = ArgumentError.new(error_message)
|
54
|
+
raise invalid_name unless valid_name?(name)
|
55
|
+
end
|
56
|
+
|
57
|
+
def valid_name?(name)
|
58
|
+
name == name.gsub(/[^a-z0-9_]/, '')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.eval(check_point1, check_point2, time_value = :string)
|
63
|
+
time_value_validation(time_value)
|
64
|
+
|
65
|
+
time_diff = check_point1 - check_point2
|
66
|
+
|
67
|
+
udiff = time_diff[:u_diff]
|
68
|
+
sdiff = time_diff[:s_diff]
|
69
|
+
cudiff = time_diff[:cu_diff]
|
70
|
+
csdiff = time_diff[:cs_diff]
|
71
|
+
realdiff = time_diff[:r_diff]
|
72
|
+
|
73
|
+
report = Benchmark::Tms.new(udiff, sdiff, cudiff, csdiff, realdiff).to_s
|
74
|
+
|
75
|
+
values = report_to_values(report)
|
76
|
+
|
77
|
+
log_table(values, check_point1.name, check_point2.name)
|
78
|
+
|
79
|
+
times_to_hash(values, time_value)
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.time_value_validation(value_type)
|
83
|
+
error_message = "time value can be :string or :float/:number"
|
84
|
+
new_error = ArgumentError.new(error_message)
|
85
|
+
|
86
|
+
raise new_error unless TIME_VALUES.include?(value_type)
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.log_table(times, name1, name2)
|
90
|
+
max_width = (times.map(&:length).max + 2)
|
91
|
+
title = set_title(name1, name2, max_width)
|
92
|
+
|
93
|
+
top_divider = TABLE_ELEMENTS[:top_divider]
|
94
|
+
top_row = TABLE_ELEMENTS[:top_row]
|
95
|
+
mid_divider = TABLE_ELEMENTS[:mid_divider]
|
96
|
+
bot_row = TABLE_ELEMENTS[:bot_row]
|
97
|
+
bot_divider = TABLE_ELEMENTS[:bot_divider]
|
98
|
+
|
99
|
+
times.each_with_index do |val, i|
|
100
|
+
top_divider << ("-" * max_width)
|
101
|
+
mid_divider << ("-" * max_width)
|
102
|
+
bot_divider << ("-" * max_width)
|
103
|
+
|
104
|
+
if i == (times.length - 1)
|
105
|
+
top_divider << TABLE_ELEMENTS[:top_right]
|
106
|
+
mid_divider << TABLE_ELEMENTS[:mid_right]
|
107
|
+
bot_divider << TABLE_ELEMENTS[:bot_right]
|
108
|
+
else
|
109
|
+
top_divider << TABLE_ELEMENTS[:top_center]
|
110
|
+
mid_divider << TABLE_ELEMENTS[:mid_center]
|
111
|
+
bot_divider << TABLE_ELEMENTS[:bot_center]
|
112
|
+
end
|
113
|
+
|
114
|
+
top_row << TITLES[i].center(max_width) + "|"
|
115
|
+
bot_row << val.center(max_width) + "|"
|
116
|
+
end
|
117
|
+
|
118
|
+
log_and_enter(title, top_divider, top_row, mid_divider, bot_row, bot_divider)
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.set_title(name1, name2, width)
|
122
|
+
message = "Runtime between #{name1} and #{name2}"
|
123
|
+
width = (width * 4) + 5
|
124
|
+
|
125
|
+
message.center(width, "=")
|
126
|
+
end
|
127
|
+
|
128
|
+
def self.log_and_enter(*lines)
|
129
|
+
lines.each { |line| puts line + "\n" }
|
130
|
+
end
|
131
|
+
|
132
|
+
def self.report_to_values(report)
|
133
|
+
values = report.to_s.gsub(/(\(|\))/, '').split(' ')
|
134
|
+
|
135
|
+
values[-1] = values[-1] + "(s)"
|
136
|
+
|
137
|
+
values
|
138
|
+
end
|
139
|
+
|
140
|
+
def self.times_to_hash(times, value_type)
|
141
|
+
times_hash = {}
|
142
|
+
|
143
|
+
TITLES.each_with_index do |title, i|
|
144
|
+
val = i == (TITLES.length - 1) ? times[i][0..-4] : times[i]
|
145
|
+
|
146
|
+
output_val = case value_type
|
147
|
+
when :string
|
148
|
+
val
|
149
|
+
else
|
150
|
+
str_to_float(val)
|
151
|
+
end
|
152
|
+
|
153
|
+
times_hash[title] = output_val
|
154
|
+
end
|
155
|
+
|
156
|
+
times_hash
|
157
|
+
end
|
158
|
+
|
159
|
+
def self.str_to_float(str)
|
160
|
+
str.to_f / 1_000_000
|
161
|
+
end
|
162
|
+
|
163
|
+
private_constant :TITLES, :TIME_VALUES, :TABLE_ELEMENTS
|
164
|
+
|
165
|
+
private_class_method :time_value_validation,
|
166
|
+
:log_table,
|
167
|
+
:log_and_enter,
|
168
|
+
:report_to_values,
|
169
|
+
:times_to_hash,
|
170
|
+
:str_to_float,
|
171
|
+
:set_title
|
172
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hop_timer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alican Sungur
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '12.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '12.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest-reporters
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: coveralls
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: A ruby gem that calculates runtime between user defined checkpoints.
|
98
|
+
email:
|
99
|
+
- sunguralican@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rubocop.yml"
|
106
|
+
- ".rubocop_todo.yml"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- hop_timer.gemspec
|
115
|
+
- lib/hop_timer.rb
|
116
|
+
- lib/hop_timer/version.rb
|
117
|
+
homepage: https://github.com/asungur/hop_timer
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata:
|
121
|
+
homepage_uri: https://github.com/asungur/hop_timer
|
122
|
+
source_code_uri: https://github.com/asungur/hop_timer
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 2.3.0
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubygems_version: 3.0.6
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: A tool that measures runtime between checkpoints
|
142
|
+
test_files: []
|