benchify 0.1.0

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.
Files changed (7) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +54 -0
  4. data/benchify.gemspec +28 -0
  5. data/bin/benchify +39 -0
  6. data/lib/benchify.rb +74 -0
  7. metadata +80 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 02f60ea5575a2eaa1de387bb7631625c9c7c8ffa373b1f77f6c33e9dc9faf47b
4
+ data.tar.gz: 0025bd883e6b174893ff6acfb3a4125a457ca629639656037c43a03be5ba5677
5
+ SHA512:
6
+ metadata.gz: 17f5037e570a19dafa806867b5623e0ac73de38205ed8c1abfe73daa1929a2f94be811ff5a5ef238b5451975886100c1a98121644f1842b7a558b5cd6ec87f68
7
+ data.tar.gz: 2853908b8eabded8dd289dd0ee53b6f45ef377ba3e336234350be7bf5a479d8703a6b6dfb65b8d478b004d10f4d837bcca8a0cddfd1abe7a63caf826171b20fd
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 decentralizuj
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Benchify
2
+
3
+ **Benchmark Source-Code:**
4
+
5
+ ```ruby
6
+ # #measure is alias for #call
7
+
8
+ benchmark = Benchify.new
9
+ # or
10
+ benchmark = Benchmark.new
11
+
12
+
13
+ benchmark.call { YOUR CODE HERE }
14
+ # or
15
+ benchmark.measure do
16
+ # YOUR CODE HERE
17
+ end
18
+ ```
19
+
20
+ **Benchmark Terminal:**
21
+
22
+ Make sure your script has environment defined ( shebang )
23
+
24
+ ` #!/usr/bin/env ruby `
25
+
26
+ ```ruby
27
+ benchify SCRIPT-1.rb SCRIPT-2.py SCRIPT-3.sh
28
+ ```
29
+
30
+ # About
31
+
32
+ ```ruby
33
+ benchmark = Benchmark.new
34
+ benchmark.call { ... }
35
+
36
+ Attributes:
37
+
38
+ benchmark.message
39
+ benchmark.type
40
+ benchmark.start
41
+ benchmark.end
42
+ benchmark.total
43
+ benchmark.time
44
+ benchmark.result
45
+ benchmark.in_seconds
46
+ benchmark.in_minutes
47
+ benchmark.in_hours
48
+ ```
49
+
50
+ # TO-DO
51
+
52
+ * Documentation
53
+ * Save output
54
+ * Self methods ( ms, seconds, minutes, hours )
data/benchify.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'benchify'
5
+ s.version = '0.1.0'
6
+ s.summary = 'Benchmark measures for Code and/or Terminal'
7
+ s.description = <<~DESC
8
+ Benchmark Ruby methods from source code, or any script from terminal.
9
+ Access object data for analysis.
10
+ DESC
11
+ s.authors = ['decentralizuj']
12
+ s.files = ['lib/benchify.rb']
13
+ s.homepage = 'https://github.com/decentralizuj/benchify'
14
+ s.license = 'MIT'
15
+
16
+ s.metadata['source_code_uri'] = 'https://github.com/decentralizuj/benchify'
17
+ s.metadata['bug_tracker_uri'] = 'https://github.com/decentralizuj/benchify/issues'
18
+
19
+ s.files = ['bin/benchify', 'lib/benchify.rb', 'LICENSE', 'README.md', 'benchify.gemspec']
20
+ s.bindir = 'bin'
21
+ s.executables = ['benchify']
22
+ s.require_paths = ['lib']
23
+
24
+ s.add_development_dependency 'bundler'
25
+ s.add_development_dependency 'rake'
26
+ end
27
+
28
+
data/bin/benchify ADDED
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/benchify'
4
+
5
+ if ARGV.empty?
6
+
7
+ puts
8
+ puts " $ benchify script_1.rb script_2.py script_3.sh"
9
+ puts
10
+
11
+ else
12
+
13
+ benchmark = Benchify.new
14
+
15
+ ARGV.each do |script|
16
+
17
+ if File.executable?(script)
18
+
19
+ benchmark.measure { system "./#{script}" }
20
+ puts benchmark.result
21
+
22
+ else
23
+
24
+ puts "[!] NOT EXECUTABLE!"
25
+ puts "[*] Do you want to give [#{script}] executable permission?"
26
+
27
+ answer = STDIN.gets.chomp!
28
+
29
+ unless %w[y Y yes YES].include? answer
30
+ next
31
+ else
32
+ system "sudo chmod +x #{script}"
33
+ benchmark.measure { system "./#{script}" }
34
+ puts benchmark.data
35
+ end
36
+
37
+ end
38
+ end
39
+ end
data/lib/benchify.rb ADDED
@@ -0,0 +1,74 @@
1
+ class Benchify
2
+
3
+ MESSAGE = 'processing time:'
4
+
5
+ attr_reader :time, :message, :type, :total, :data, :start, :end
6
+ attr_reader :in_seconds, :in_hours, :in_minutes, :in_milliseconds
7
+
8
+ alias result data
9
+
10
+ alias in_ms in_milliseconds
11
+ alias in_milli in_milliseconds
12
+
13
+ alias in_h in_hours
14
+
15
+ alias in_sec in_seconds
16
+
17
+ alias in_min in_minutes
18
+
19
+
20
+ def initialize( type = :sec, message = nil )
21
+
22
+ case type
23
+ when :m, :min, :minute, :minutes then :min
24
+ when :ms, :milli, :milliseconds then :ms
25
+ when :h, :hour, :hours then :h
26
+ else :sec
27
+ end
28
+
29
+ @type = type
30
+ @message = message || MESSAGE
31
+ end
32
+
33
+
34
+ def call( msg = nil, &operation )
35
+
36
+ msg = message || @message
37
+ @start = Time.now
38
+
39
+ yield operation
40
+
41
+ @end = Time.now
42
+ @total = (@end - @start).to_f
43
+
44
+ calculate_time @type
45
+ @data = "#{msg} #{@time} #{@type}"
46
+ end
47
+
48
+ alias measure call
49
+
50
+
51
+ private
52
+
53
+
54
+ def calculate_time( type )
55
+ @in_seconds = @total.round(4)
56
+ @in_hours = (@total / 60).round(2)
57
+ @in_minutes = (@total / 360).round(2)
58
+ @in_milliseconds = (@total * 1000).round(5)
59
+ return_by_type type
60
+ end
61
+
62
+
63
+ def return_by_type( type )
64
+ case type
65
+ when :sec then time = @in_seconds
66
+ when :min then time = @in_minutes
67
+ when :ms then time = @in_milliseconds
68
+ when :h then time = @in_hours
69
+ end
70
+ return @time = time.to_s
71
+ end
72
+ end
73
+
74
+ class Benchmark < Benchify; end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: benchify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - decentralizuj
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-04-15 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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '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: '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
+ description: |
42
+ Benchmark Ruby methods from source code, or any script from terminal.
43
+ Access object data for analysis.
44
+ email:
45
+ executables:
46
+ - benchify
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - LICENSE
51
+ - README.md
52
+ - benchify.gemspec
53
+ - bin/benchify
54
+ - lib/benchify.rb
55
+ homepage: https://github.com/decentralizuj/benchify
56
+ licenses:
57
+ - MIT
58
+ metadata:
59
+ source_code_uri: https://github.com/decentralizuj/benchify
60
+ bug_tracker_uri: https://github.com/decentralizuj/benchify/issues
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubygems_version: 3.2.3
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Benchmark measures for Code and/or Terminal
80
+ test_files: []