hitimes 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +1 -1
- data/HISTORY.md +20 -3
- data/Manifest.txt +2 -17
- data/README.md +38 -43
- data/hitimes.gemspec +26 -0
- data/lib/hitimes/initialize.rb +83 -44
- data/lib/hitimes/instant.rb +9 -33
- data/lib/hitimes/interval.rb +15 -15
- data/lib/hitimes/metric.rb +18 -22
- data/lib/hitimes/mutexed_stats.rb +2 -4
- data/lib/hitimes/paths.rb +16 -14
- data/lib/hitimes/stats.rb +33 -33
- data/lib/hitimes/timed_metric.rb +43 -42
- data/lib/hitimes/timed_value_metric.rb +43 -43
- data/lib/hitimes/value_metric.rb +16 -15
- data/lib/hitimes/version.rb +3 -1
- data/lib/hitimes.rb +12 -11
- metadata +20 -113
- data/Rakefile +0 -19
- data/examples/benchmarks.rb +0 -113
- data/examples/stats.rb +0 -31
- data/spec/hitimes_spec.rb +0 -24
- data/spec/interval_spec.rb +0 -136
- data/spec/metric_spec.rb +0 -28
- data/spec/mutex_stats_spec.rb +0 -29
- data/spec/paths_spec.rb +0 -11
- data/spec/spec_helper.rb +0 -11
- data/spec/stats_spec.rb +0 -98
- data/spec/timed_metric_spec.rb +0 -155
- data/spec/timed_value_metric_spec.rb +0 -171
- data/spec/value_metric_spec.rb +0 -108
- data/spec/version_spec.rb +0 -7
- data/tasks/default.rake +0 -242
- data/tasks/this.rb +0 -208
- /data/{LICENSE → LICENSE.txt} +0 -0
data/lib/hitimes/value_metric.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# Copyright (c) 2008, 2009 Jeremy Hinegardner
|
3
5
|
# All rights reserved. See LICENSE and/or COPYING for details.
|
4
6
|
#++
|
5
7
|
|
6
|
-
require
|
8
|
+
require "forwardable"
|
7
9
|
module Hitimes
|
8
10
|
#
|
9
11
|
# A ValueMetric holds the data from measuring a single value over a period of
|
@@ -12,15 +14,14 @@ module Hitimes
|
|
12
14
|
#
|
13
15
|
# A good example of a ValueMetric is measuring the number of items in a queue.
|
14
16
|
#
|
15
|
-
# A ValueMetric contains a Stats object, therefore ValueMetric has +count+, +max+,
|
17
|
+
# A ValueMetric contains a Stats object, therefore ValueMetric has +count+, +max+,
|
16
18
|
# +mean+, +min+, +stddev+, +sum+, +sumsq+ methods that delegate to that Stats
|
17
19
|
# object for convenience.
|
18
20
|
#
|
19
21
|
class ValueMetric < Metric
|
20
|
-
|
21
22
|
# holds all the statistics
|
22
23
|
attr_reader :stats
|
23
|
-
|
24
|
+
|
24
25
|
#
|
25
26
|
# :call-seq:
|
26
27
|
# ValueMetric.new( 'my_metric' ) -> ValueMetric
|
@@ -29,8 +30,8 @@ module Hitimes
|
|
29
30
|
# Create a new ValueMetric giving it a name and additional data.
|
30
31
|
# +additional_data+ may be anything that follows the +to_hash+ protocol.
|
31
32
|
#
|
32
|
-
def initialize(
|
33
|
-
super(
|
33
|
+
def initialize(name, additional_data = {})
|
34
|
+
super(name, additional_data)
|
34
35
|
@stats = Stats.new
|
35
36
|
end
|
36
37
|
|
@@ -40,12 +41,12 @@ module Hitimes
|
|
40
41
|
#
|
41
42
|
# Give the +value+ as the measurement to the metric. The value is returned
|
42
43
|
#
|
43
|
-
def measure(
|
44
|
-
@sampling_start_time ||=
|
44
|
+
def measure(value)
|
45
|
+
@sampling_start_time ||= utc_microseconds
|
45
46
|
@sampling_start_interval ||= Interval.now
|
46
47
|
|
47
|
-
@stats.update(
|
48
|
-
|
48
|
+
@stats.update(value)
|
49
|
+
|
49
50
|
# update the length of time we have been sampling
|
50
51
|
@sampling_delta = @sampling_start_interval.duration_so_far
|
51
52
|
end
|
@@ -53,15 +54,15 @@ module Hitimes
|
|
53
54
|
#
|
54
55
|
# :call-seq:
|
55
56
|
# metric.to_hash -> Hash
|
56
|
-
#
|
57
|
+
#
|
57
58
|
# Convert the metric to a hash
|
58
59
|
#
|
59
60
|
def to_hash
|
60
|
-
|
61
|
-
(Stats::STATS - %w[
|
62
|
-
|
61
|
+
result = super
|
62
|
+
(Stats::STATS - %w[rate]).each do |stat|
|
63
|
+
result[stat] = send(stat)
|
63
64
|
end
|
64
|
-
|
65
|
+
result
|
65
66
|
end
|
66
67
|
|
67
68
|
# forward appropriate calls directly to the stats object
|
data/lib/hitimes/version.rb
CHANGED
data/lib/hitimes.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# Copyright (c) 2008 Jeremy Hinegardner
|
3
5
|
# All rights reserved. See LICENSE and/or COPYING for details.
|
@@ -23,16 +25,15 @@ module Hitimes
|
|
23
25
|
Hitimes::Interval.measure(&block)
|
24
26
|
end
|
25
27
|
end
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
30
|
-
|
31
|
-
require 'hitimes/stats'
|
32
|
-
require 'hitimes/mutexed_stats'
|
28
|
+
require "hitimes/paths"
|
29
|
+
require "hitimes/version"
|
30
|
+
require "hitimes/instant"
|
31
|
+
require "hitimes/interval"
|
33
32
|
|
34
|
-
require
|
35
|
-
require
|
36
|
-
require 'hitimes/timed_metric'
|
37
|
-
require 'hitimes/timed_value_metric'
|
33
|
+
require "hitimes/stats"
|
34
|
+
require "hitimes/mutexed_stats"
|
38
35
|
|
36
|
+
require "hitimes/metric"
|
37
|
+
require "hitimes/value_metric"
|
38
|
+
require "hitimes/timed_metric"
|
39
|
+
require "hitimes/timed_value_metric"
|
metadata
CHANGED
@@ -1,105 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hitimes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Hinegardner
|
8
|
-
autorequire:
|
9
|
-
bindir:
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
name: rake
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '12.3'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '12.3'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: minitest
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '5.5'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '5.5'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rdoc
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '6.2'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '6.2'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: json
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '2.2'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '2.2'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: simplecov
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0.17'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0.17'
|
83
|
-
description: A fast, high resolution timer library for recording peformance metrics.
|
84
|
-
* (http://github.com/copiousfreetime/hitimes) * (http://github.com/copiousfreetime/hitimes)
|
85
|
-
* email jeremy at copiousfreetime dot org * `git clone url git://github.com/copiousfreetime/hitimes.git`
|
11
|
+
date: 2024-05-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A fast, high resolution timer library for recording performance metrics.
|
86
14
|
email: jeremy@copiousfreetime.org
|
87
15
|
executables: []
|
88
16
|
extensions: []
|
89
17
|
extra_rdoc_files:
|
90
18
|
- CONTRIBUTING.md
|
91
19
|
- HISTORY.md
|
20
|
+
- LICENSE.txt
|
92
21
|
- Manifest.txt
|
93
22
|
- README.md
|
94
23
|
files:
|
95
24
|
- CONTRIBUTING.md
|
96
25
|
- HISTORY.md
|
97
|
-
- LICENSE
|
26
|
+
- LICENSE.txt
|
98
27
|
- Manifest.txt
|
99
28
|
- README.md
|
100
|
-
-
|
101
|
-
- examples/benchmarks.rb
|
102
|
-
- examples/stats.rb
|
29
|
+
- hitimes.gemspec
|
103
30
|
- lib/hitimes.rb
|
104
31
|
- lib/hitimes/initialize.rb
|
105
32
|
- lib/hitimes/instant.rb
|
@@ -112,24 +39,15 @@ files:
|
|
112
39
|
- lib/hitimes/timed_value_metric.rb
|
113
40
|
- lib/hitimes/value_metric.rb
|
114
41
|
- lib/hitimes/version.rb
|
115
|
-
- spec/hitimes_spec.rb
|
116
|
-
- spec/interval_spec.rb
|
117
|
-
- spec/metric_spec.rb
|
118
|
-
- spec/mutex_stats_spec.rb
|
119
|
-
- spec/paths_spec.rb
|
120
|
-
- spec/spec_helper.rb
|
121
|
-
- spec/stats_spec.rb
|
122
|
-
- spec/timed_metric_spec.rb
|
123
|
-
- spec/timed_value_metric_spec.rb
|
124
|
-
- spec/value_metric_spec.rb
|
125
|
-
- spec/version_spec.rb
|
126
|
-
- tasks/default.rake
|
127
|
-
- tasks/this.rb
|
128
42
|
homepage: http://github.com/copiousfreetime/hitimes
|
129
43
|
licenses:
|
130
44
|
- ISC
|
131
|
-
metadata:
|
132
|
-
|
45
|
+
metadata:
|
46
|
+
bug_tracker_uri: https://github.com/copiousfreetime/hitimes/issues
|
47
|
+
changelog_uri: https://github.com/copiousfreetime/hitimes/blob/master/HISTORY.md
|
48
|
+
homepage_uri: https://github.com/copiousfreetime/hitimes
|
49
|
+
source_code_uri: https://github.com/copiousfreetime/hitimes
|
50
|
+
post_install_message:
|
133
51
|
rdoc_options:
|
134
52
|
- "--main"
|
135
53
|
- README.md
|
@@ -141,26 +59,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
141
59
|
requirements:
|
142
60
|
- - ">="
|
143
61
|
- !ruby/object:Gem::Version
|
144
|
-
version:
|
62
|
+
version: 3.0.0
|
145
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
64
|
requirements:
|
147
65
|
- - ">="
|
148
66
|
- !ruby/object:Gem::Version
|
149
67
|
version: '0'
|
150
68
|
requirements: []
|
151
|
-
rubygems_version: 3.
|
152
|
-
signing_key:
|
69
|
+
rubygems_version: 3.5.9
|
70
|
+
signing_key:
|
153
71
|
specification_version: 4
|
154
|
-
summary: A fast, high resolution timer library for recording
|
155
|
-
test_files:
|
156
|
-
- spec/hitimes_spec.rb
|
157
|
-
- spec/interval_spec.rb
|
158
|
-
- spec/metric_spec.rb
|
159
|
-
- spec/mutex_stats_spec.rb
|
160
|
-
- spec/paths_spec.rb
|
161
|
-
- spec/spec_helper.rb
|
162
|
-
- spec/stats_spec.rb
|
163
|
-
- spec/timed_metric_spec.rb
|
164
|
-
- spec/timed_value_metric_spec.rb
|
165
|
-
- spec/value_metric_spec.rb
|
166
|
-
- spec/version_spec.rb
|
72
|
+
summary: A fast, high resolution timer library for recording performance metrics.
|
73
|
+
test_files: []
|
data/Rakefile
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# vim: syntax=ruby
|
2
|
-
load 'tasks/this.rb'
|
3
|
-
|
4
|
-
This.name = "hitimes"
|
5
|
-
This.author = "Jeremy Hinegardner"
|
6
|
-
This.email = "jeremy@copiousfreetime.org"
|
7
|
-
This.homepage = "http://github.com/copiousfreetime/#{ This.name }"
|
8
|
-
|
9
|
-
This.ruby_gemspec do |spec|
|
10
|
-
spec.add_development_dependency( 'rake' , '~> 12.3')
|
11
|
-
spec.add_development_dependency( 'minitest' , '~> 5.5' )
|
12
|
-
spec.add_development_dependency( 'rdoc' , '~> 6.2' )
|
13
|
-
spec.add_development_dependency( 'json' , '~> 2.2' )
|
14
|
-
spec.add_development_dependency( 'simplecov' , '~> 0.17' )
|
15
|
-
|
16
|
-
spec.license = "ISC"
|
17
|
-
end
|
18
|
-
|
19
|
-
load 'tasks/default.rake'
|
data/examples/benchmarks.rb
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
require 'benchmark'
|
2
|
-
require 'time'
|
3
|
-
|
4
|
-
#
|
5
|
-
# this is all here in case this example is run from the examples directory
|
6
|
-
#
|
7
|
-
begin
|
8
|
-
require 'hitimes'
|
9
|
-
rescue LoadError => le
|
10
|
-
ext_path = File.expand_path( File.join( File.dirname( __FILE__ ), "..", "ext" ) )
|
11
|
-
lib_path = File.expand_path( File.join( File.dirname( __FILE__ ), "..", "lib" ) )
|
12
|
-
if $:.include?( ext_path ) then
|
13
|
-
raise le
|
14
|
-
end
|
15
|
-
$: << ext_path
|
16
|
-
$: << lib_path
|
17
|
-
retry
|
18
|
-
end
|
19
|
-
|
20
|
-
#----------------------------------------------------------------------
|
21
|
-
# test program to look at the performance sampling time durations using
|
22
|
-
# different methods
|
23
|
-
#----------------------------------------------------------------------
|
24
|
-
|
25
|
-
include Benchmark
|
26
|
-
|
27
|
-
#
|
28
|
-
# Normal apprach to Interval usage
|
29
|
-
#
|
30
|
-
def hitimes_duration_i1
|
31
|
-
i = Hitimes::Interval.new
|
32
|
-
i.start
|
33
|
-
i.stop
|
34
|
-
end
|
35
|
-
|
36
|
-
#
|
37
|
-
# Use the easy access method to start stop an interval
|
38
|
-
#
|
39
|
-
def hitimes_duration_i2
|
40
|
-
Hitimes::Interval.now.stop
|
41
|
-
end
|
42
|
-
|
43
|
-
#
|
44
|
-
# Use a new timer each time
|
45
|
-
#
|
46
|
-
def hitimes_duration_t1
|
47
|
-
Hitimes::TimedMetric.now('duration_t1').stop
|
48
|
-
end
|
49
|
-
|
50
|
-
#
|
51
|
-
# reuse the same timer over and over
|
52
|
-
#
|
53
|
-
HT2= Hitimes::TimedMetric.new( 'duration_t2' )
|
54
|
-
def hitimes_duration_t2
|
55
|
-
HT2.start
|
56
|
-
HT2.stop
|
57
|
-
end
|
58
|
-
|
59
|
-
HT3 = Hitimes::TimedMetric.new( 'duration_t3' )
|
60
|
-
def hitimes_duration_t3
|
61
|
-
HT3.measure { nil }
|
62
|
-
end
|
63
|
-
|
64
|
-
#
|
65
|
-
# Check out the speed of the TimedValueMetric too
|
66
|
-
#
|
67
|
-
def hitimes_duration_tv1
|
68
|
-
Hitimes::TimedValueMetric.now( 'duration_tv1' ).stop( 42 )
|
69
|
-
end
|
70
|
-
|
71
|
-
HTV2 = Hitimes::TimedValueMetric.new( 'duration_tv2' )
|
72
|
-
def hitimes_duration_tv2
|
73
|
-
HTV2.start
|
74
|
-
HTV2.stop( 42 )
|
75
|
-
end
|
76
|
-
|
77
|
-
HTV3 = Hitimes::TimedValueMetric.new( 'duration_tv3' )
|
78
|
-
def hitimes_duration_tv3
|
79
|
-
HTV3.measure( 42 ) { nil }
|
80
|
-
end
|
81
|
-
|
82
|
-
#
|
83
|
-
# use the Struct::Tms values and return the difference in User time between 2
|
84
|
-
# successive calls
|
85
|
-
#
|
86
|
-
def process_duration
|
87
|
-
t1 = Process.times.utime
|
88
|
-
Process.times.utime - t1
|
89
|
-
end
|
90
|
-
|
91
|
-
#
|
92
|
-
# Take 2 times and subtract one from the other
|
93
|
-
#
|
94
|
-
def time_duration
|
95
|
-
t1 = Time.now.to_f
|
96
|
-
Time.now.to_f - t1
|
97
|
-
end
|
98
|
-
|
99
|
-
|
100
|
-
puts "Testing time sampling 100,000 times"
|
101
|
-
|
102
|
-
bm(30) do |x|
|
103
|
-
x.report("Process") { 100_000.times { process_duration } }
|
104
|
-
x.report("Time") { 100_000.times { time_duration } }
|
105
|
-
x.report("Hitimes::TimedMetric 1") { 100_000.times { hitimes_duration_t1 } }
|
106
|
-
x.report("Hitimes::TimedMetric 2") { 100_000.times { hitimes_duration_t2 } }
|
107
|
-
x.report("Hitimes::TimedMetric 3") { 100_000.times { hitimes_duration_t3 } }
|
108
|
-
x.report("Hitimes::Interval 1") { 100_000.times { hitimes_duration_i1 } }
|
109
|
-
x.report("Hitimes::Interval 2") { 100_000.times { hitimes_duration_i2 } }
|
110
|
-
x.report("Hitimes::TimedValueMetric 1") { 100_000.times { hitimes_duration_tv1 } }
|
111
|
-
x.report("Hitimes::TimedValueMetric 2") { 100_000.times { hitimes_duration_tv2 } }
|
112
|
-
x.report("Hitimes::TimedValueMetric 3") { 100_000.times { hitimes_duration_tv3 } }
|
113
|
-
end
|
data/examples/stats.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# this is all here in case this example is run from the examples directory
|
3
|
-
#
|
4
|
-
begin
|
5
|
-
require 'hitimes'
|
6
|
-
rescue LoadError => le
|
7
|
-
%w[ ext lib ].each do |p|
|
8
|
-
path = File.expand_path( File.join( File.dirname( __FILE__ ), "..", p ) )
|
9
|
-
if $:.include?( path ) then
|
10
|
-
raise le
|
11
|
-
end
|
12
|
-
$: << path
|
13
|
-
end
|
14
|
-
retry
|
15
|
-
end
|
16
|
-
|
17
|
-
s = Hitimes::Stats.new
|
18
|
-
dir = ARGV.shift || Dir.pwd
|
19
|
-
Dir.entries( dir ).each do |entry|
|
20
|
-
fs = File.stat( entry )
|
21
|
-
if fs.file? then
|
22
|
-
s.update( fs.size )
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
Hitimes::Stats::STATS.each do |m|
|
27
|
-
puts "#{m.rjust(6)} : #{s.send( m ) }"
|
28
|
-
end
|
29
|
-
|
30
|
-
puts s.to_hash.inspect
|
31
|
-
|
data/spec/hitimes_spec.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Hitimes do
|
4
|
-
it "can time a block of code" do
|
5
|
-
d = Hitimes.measure do
|
6
|
-
sleep 0.2
|
7
|
-
end
|
8
|
-
_(d).must_be_close_to(0.2, 0.002)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "raises an error if measure is called with no block" do
|
12
|
-
_(lambda{ Hitimes.measure }).must_raise( Hitimes::Error )
|
13
|
-
end
|
14
|
-
|
15
|
-
it "has the raw instant value" do
|
16
|
-
v = Hitimes.raw_instant
|
17
|
-
_(v).must_be :>, 0
|
18
|
-
end
|
19
|
-
|
20
|
-
it "has access to the instant conversion factor" do
|
21
|
-
f = Hitimes::INSTANT_CONVERSION_FACTOR
|
22
|
-
_(f).must_be :>, 0
|
23
|
-
end
|
24
|
-
end
|
data/spec/interval_spec.rb
DELETED
@@ -1,136 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Hitimes::Interval do
|
4
|
-
it "raises an error if duration is called on a non-started interval" do
|
5
|
-
i = Hitimes::Interval.new
|
6
|
-
_(lambda{ i.duration }).must_raise( Hitimes::Error, /\AAttempt to report a duration on an interval that has not started\Z/ )
|
7
|
-
end
|
8
|
-
|
9
|
-
it "raises an error if stop is called on a non-started interval" do
|
10
|
-
i = Hitimes::Interval.new
|
11
|
-
_(lambda { i.stop }).must_raise( Hitimes::Error, /\AAttempt to stop an interval that has not started\Z/ )
|
12
|
-
end
|
13
|
-
|
14
|
-
it "knows if it has been started" do
|
15
|
-
i = Hitimes::Interval.new
|
16
|
-
_(i.started?).must_equal false
|
17
|
-
|
18
|
-
i.start
|
19
|
-
_(i.started?).must_equal true
|
20
|
-
end
|
21
|
-
|
22
|
-
it "knows if it has been stopped" do
|
23
|
-
i = Hitimes::Interval.new
|
24
|
-
i.start
|
25
|
-
_(i.stopped?).must_equal false
|
26
|
-
i.stop
|
27
|
-
_(i.stopped?).must_equal true
|
28
|
-
end
|
29
|
-
|
30
|
-
it "knows if it is currently running" do
|
31
|
-
i = Hitimes::Interval.new
|
32
|
-
_(i.running?).must_equal false
|
33
|
-
i.start
|
34
|
-
_(i.running?).must_equal true
|
35
|
-
i.stop
|
36
|
-
_(i.running?).must_equal false
|
37
|
-
end
|
38
|
-
|
39
|
-
it "can time a block of code" do
|
40
|
-
d = Hitimes::Interval.measure do
|
41
|
-
sleep 0.2
|
42
|
-
end
|
43
|
-
_(d).must_be_close_to(0.2, 0.002)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "raises an error if measure is called with no block" do
|
47
|
-
_(lambda{ Hitimes::Interval.measure }).must_raise( Hitimes::Error, /\ANo block given to Interval.measure\Z/ )
|
48
|
-
end
|
49
|
-
|
50
|
-
it "creates an interval via #now" do
|
51
|
-
i = Hitimes::Interval.now
|
52
|
-
_(i.started?).must_equal true
|
53
|
-
_(i.stopped?).must_equal false
|
54
|
-
end
|
55
|
-
|
56
|
-
it "calling duration multiple times returns successivly grater durations" do
|
57
|
-
i = Hitimes::Interval.new
|
58
|
-
i.start
|
59
|
-
y = i.duration
|
60
|
-
z = i.duration
|
61
|
-
_(z).must_be :>, y
|
62
|
-
end
|
63
|
-
|
64
|
-
it "calling start multiple times on has no effect after the first call" do
|
65
|
-
i = Hitimes::Interval.new
|
66
|
-
_(i.start).must_equal true
|
67
|
-
x = i.start_instant
|
68
|
-
_(i.start_instant).must_be :>, 0
|
69
|
-
_(i.start).must_equal false
|
70
|
-
_(x).must_equal i.start_instant
|
71
|
-
end
|
72
|
-
|
73
|
-
it "returns the duration on the first call to stop" do
|
74
|
-
i = Hitimes::Interval.now
|
75
|
-
d = i.stop
|
76
|
-
_(d).must_be_instance_of( Float )
|
77
|
-
end
|
78
|
-
|
79
|
-
it "calling stop multiple times on has no effect after the first call" do
|
80
|
-
i = Hitimes::Interval.new
|
81
|
-
_(i.start).must_equal true
|
82
|
-
i.stop
|
83
|
-
|
84
|
-
x = i.stop_instant
|
85
|
-
_(i.stop_instant).must_be :>, 0
|
86
|
-
_(i.stop).must_equal false
|
87
|
-
_(x).must_equal i.stop_instant
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
it "duration does not change after stop is calledd" do
|
92
|
-
i = Hitimes::Interval.new
|
93
|
-
i.start
|
94
|
-
x = i.stop
|
95
|
-
y = i.duration
|
96
|
-
_(i.stop).must_equal false
|
97
|
-
|
98
|
-
z = i.duration
|
99
|
-
|
100
|
-
_(x).must_equal y
|
101
|
-
_(x).must_equal z
|
102
|
-
|
103
|
-
_(y).must_equal z
|
104
|
-
end
|
105
|
-
|
106
|
-
it "can return how much time has elapsed from the start without stopping the interval" do
|
107
|
-
i = Hitimes::Interval.new
|
108
|
-
i.start
|
109
|
-
x = i.duration_so_far
|
110
|
-
_(i.running?).must_equal true
|
111
|
-
y = i.duration_so_far
|
112
|
-
i.stop
|
113
|
-
_(x).must_be :<, y
|
114
|
-
_(x).must_be :<, i.duration
|
115
|
-
_(y).must_be :<, i.duration
|
116
|
-
end
|
117
|
-
|
118
|
-
describe "#split" do
|
119
|
-
|
120
|
-
it "creates a new Interval object" do
|
121
|
-
i = Hitimes::Interval.new
|
122
|
-
i.start
|
123
|
-
i2 = i.split
|
124
|
-
_(i.object_id).wont_equal i2.object_id
|
125
|
-
end
|
126
|
-
|
127
|
-
it "with the stop instant equivialent to the previous Interval's start instant" do
|
128
|
-
i = Hitimes::Interval.new
|
129
|
-
i.start
|
130
|
-
i2 = i.split
|
131
|
-
_(i.stop_instant).must_equal i2.start_instant
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
end
|
136
|
-
|
data/spec/metric_spec.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Hitimes::Metric do
|
4
|
-
before( :each ) do
|
5
|
-
@metric = Hitimes::Metric.new( "testing" )
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'has a name' do
|
9
|
-
_(@metric.name).must_equal "testing"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "has associated data from initialization" do
|
13
|
-
m = Hitimes::Metric.new( "more-data", 'foo' => 'bar', 'this' => 'that' )
|
14
|
-
_(m.additional_data['foo']).must_equal 'bar'
|
15
|
-
_(m.additional_data['this']).must_equal 'that'
|
16
|
-
|
17
|
-
m = Hitimes::Metric.new( "more-data", { 'foo' => 'bar', 'this' => 'that' } )
|
18
|
-
_(m.additional_data['foo']).must_equal 'bar'
|
19
|
-
_(m.additional_data['this']).must_equal 'that'
|
20
|
-
end
|
21
|
-
|
22
|
-
it "initially has no sampling times" do
|
23
|
-
_(@metric.sampling_start_time).must_be_nil
|
24
|
-
_(@metric.sampling_stop_time).must_be_nil
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
|
data/spec/mutex_stats_spec.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Hitimes::MutexedStats do
|
4
|
-
before( :each ) do
|
5
|
-
@threads = 5
|
6
|
-
@iters = 10_000
|
7
|
-
@final_value = @threads * @iters
|
8
|
-
end
|
9
|
-
|
10
|
-
def run_with_scissors( stats, threads, iters )
|
11
|
-
spool = []
|
12
|
-
threads.times do |t|
|
13
|
-
spool << Thread.new { iters.times{ stats.update( 1 ) } }
|
14
|
-
end
|
15
|
-
spool.each { |t| t.join }
|
16
|
-
return stats
|
17
|
-
end
|
18
|
-
|
19
|
-
it "Hitimes::Stats is threadsafe" do
|
20
|
-
stats = run_with_scissors( ::Hitimes::Stats.new, @threads, @iters )
|
21
|
-
_(stats.count).must_equal @final_value
|
22
|
-
end
|
23
|
-
|
24
|
-
it "has a threadsafe update" do
|
25
|
-
stats = run_with_scissors( ::Hitimes::MutexedStats.new, @threads, @iters )
|
26
|
-
_(stats.count).must_equal @final_value
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
data/spec/paths_spec.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Hitimes::Paths do
|
4
|
-
it "can access the root dir of the project" do
|
5
|
-
_(Hitimes::Paths.root_dir).must_equal File.expand_path( File.join( File.dirname( __FILE__ ), ".." ) ) + ::File::SEPARATOR
|
6
|
-
end
|
7
|
-
|
8
|
-
it "can access the lib path of the project" do
|
9
|
-
_(Hitimes::Paths.lib_path).must_equal File.expand_path( File.join( File.dirname( __FILE__ ), "..", "lib" ) ) + ::File::SEPARATOR
|
10
|
-
end
|
11
|
-
end
|