timeit 0.0.1-java

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.
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ # YARD artifacts
20
+ .yardoc
21
+ _yardoc
22
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in timeit.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 rainkinz
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
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
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ timeit
2
+ ======
3
+
4
+ Simple ruby timer
5
+
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'timeit'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install timeit
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ $:.unshift File.expand_path("../../lib", __FILE__)
2
+ require 'timeit'
3
+
4
+ Timeit.ti do |timer|
5
+ 1.upto(100) do |i|
6
+ if i % 10 == 0
7
+ timer.tick!(10)
8
+ puts "#{i} of 1000 in #{timer.duration} #{timer.rate} items/s"
9
+ end
10
+ sleep(0.1)
11
+ # timer.split! if i % 300 == 0
12
+ end
13
+ puts "Completed in #{timer.total_duration} "
14
+ end
@@ -0,0 +1,22 @@
1
+ $:.unshift File.expand_path("../../lib", __FILE__)
2
+ require 'timeit'
3
+
4
+ Timeit.ti do |ti|
5
+
6
+ total_iterations = 100
7
+ 1.upto(total_iterations) do |i|
8
+ if i % 10 == 0
9
+ ti.tick!(10)
10
+ puts "#{i} of #{total_iterations} in #{ti.duration} #{ti.rate} item/s"
11
+ end
12
+
13
+ if i % 20 == 0
14
+ puts "Split for the last 20 items was #{ti.split}, split rate #{ti.split_rate} items/s"
15
+ end
16
+
17
+ sleep(0.1)
18
+ end
19
+ puts "Completed in #{ti.total_duration} "
20
+ end
21
+
22
+
data/lib/timeit.rb ADDED
@@ -0,0 +1,66 @@
1
+ require 'timeit/version'
2
+
3
+ module Timeit
4
+ extend self
5
+
6
+ class Timer
7
+
8
+ attr_reader :start_time
9
+
10
+ def initialize(start = Time.now)
11
+ @start_time = start
12
+ @iterations = 0
13
+ @rate = 0
14
+
15
+ @split_time = start
16
+ @split_iterations = 0
17
+ @split_rate = 0
18
+ end
19
+
20
+ def duration
21
+ duration = Time.now - @start_time
22
+ @rate = @iterations / duration
23
+ duration
24
+ end
25
+
26
+ def total_duration
27
+ Time.now - @start_time
28
+ end
29
+
30
+ def split
31
+ split = Time.now - @split_time
32
+ @split_time = Time.now
33
+
34
+ @split_rate = @split_iterations / split
35
+ @split_iterations = 0
36
+
37
+ split
38
+ end
39
+
40
+ def reset_split!
41
+ @split_time = @start_time
42
+ end
43
+
44
+ def tick!(count = 1)
45
+ @iterations += count
46
+ @split_iterations += count
47
+ end
48
+
49
+ def rate
50
+ @rate
51
+ end
52
+
53
+ def split_rate
54
+ @split_rate
55
+ end
56
+
57
+ end
58
+
59
+
60
+ def ti(&block)
61
+ t = Timer.new
62
+ yield t
63
+ end
64
+
65
+ end
66
+
@@ -0,0 +1,3 @@
1
+ module Timeit
2
+ VERSION = "0.0.1"
3
+ end
data/timeit.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'timeit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "timeit"
8
+ spec.version = Timeit::VERSION
9
+ spec.authors = ["rainkinz"]
10
+ spec.email = ["brendan.grainger@gmail.com"]
11
+ spec.description = <<-TEXT
12
+ Very basic ruby timer for keeping track of the duration, splits and rate of
13
+ a block of code.
14
+ TEXT
15
+ spec.summary = %q{Track duration of a block of code}
16
+ spec.homepage = "https://github.com/rainkinz/timeit"
17
+ spec.license = "MIT"
18
+
19
+ spec.files = `git ls-files`.split($/)
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+
27
+ if !! (RUBY_PLATFORM =~ /java/)
28
+ # For some reason the pure ruby version isn't found by Bundler
29
+ spec.platform = 'java'
30
+ else
31
+ spec.platform = Gem::Platform::RUBY
32
+ end
33
+
34
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: timeit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: java
7
+ authors:
8
+ - rainkinz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.3'
21
+ none: false
22
+ requirement: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ none: false
28
+ prerelease: false
29
+ type: :development
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: !binary |-
37
+ MA==
38
+ none: false
39
+ requirement: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: !binary |-
44
+ MA==
45
+ none: false
46
+ prerelease: false
47
+ type: :development
48
+ description: |2
49
+ Very basic ruby timer for keeping track of the duration, splits and rate of
50
+ a block of code.
51
+ email:
52
+ - brendan.grainger@gmail.com
53
+ executables: []
54
+ extensions: []
55
+ extra_rdoc_files: []
56
+ files:
57
+ - ".gitignore"
58
+ - Gemfile
59
+ - LICENSE.txt
60
+ - README.md
61
+ - Rakefile
62
+ - examples/duration.rb
63
+ - examples/splits.rb
64
+ - lib/timeit.rb
65
+ - lib/timeit/version.rb
66
+ - timeit.gemspec
67
+ homepage: https://github.com/rainkinz/timeit
68
+ licenses:
69
+ - MIT
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: !binary |-
79
+ MA==
80
+ none: false
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: !binary |-
86
+ MA==
87
+ none: false
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 1.8.24
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: Track duration of a block of code
94
+ test_files: []