hitimes 0.3.0-x86-mswin32-60 → 0.4.0-x86-mswin32-60
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/HISTORY +7 -0
- data/README +9 -8
- data/ext/extconf.rb +1 -1
- data/ext/hitimes_ext.c +1 -0
- data/ext/hitimes_stats.c +5 -4
- data/ext/rbconfig-mingw.rb +2 -2
- data/ext/rbconfig.rb +2 -2
- data/gemspec.rb +0 -1
- data/lib/hitimes.rb +3 -0
- data/lib/hitimes/mutexed_stats.rb +23 -0
- data/lib/hitimes/stats.rb +29 -0
- data/lib/hitimes/version.rb +1 -1
- data/lib/hitimes_ext.so +0 -0
- data/spec/mutex_stats_spec.rb +34 -0
- data/spec/stats_spec.rb +24 -0
- data/tasks/config.rb +1 -1
- metadata +9 -14
data/HISTORY
CHANGED
@@ -1,4 +1,11 @@
|
|
1
1
|
= Changelog
|
2
|
+
== Version 0.4.0 2008-12-20
|
3
|
+
|
4
|
+
* Added new stat 'rate'
|
5
|
+
* Added new stat method to_hash
|
6
|
+
* Added MutexedStats class for threadsafe stats collection
|
7
|
+
- not needed when used in MRI 1.8.x
|
8
|
+
* remove stale dependency on mkrf
|
2
9
|
|
3
10
|
== Version 0.3.0
|
4
11
|
|
data/README
CHANGED
@@ -11,16 +11,16 @@
|
|
11
11
|
|
12
12
|
== DESCRIPTION
|
13
13
|
|
14
|
-
Hitimes is a fast, high resolution timer library for recording
|
15
|
-
metrics. It uses the appropriate C method calls for each
|
16
|
-
highest granularity time increments possible.
|
14
|
+
Hitimes is a fast, high resolution timer library for recording
|
15
|
+
performance metrics. It uses the appropriate C method calls for each
|
16
|
+
system to get the highest granularity time increments possible.
|
17
17
|
|
18
|
-
It currently supports any system with the POSIX call clock_gettime()
|
19
|
-
|
18
|
+
It currently supports any system with the POSIX call clock_gettime(),
|
19
|
+
Mac OS X and Windows.
|
20
20
|
|
21
|
-
Using Hitimes can be faster than using a series of Time.new calls, and
|
22
|
-
have a much higher granularity. It is definitely faster than
|
23
|
-
Process.times.
|
21
|
+
Using Hitimes can be faster than using a series of Time.new calls, and
|
22
|
+
it will have a much higher granularity. It is definitely faster than
|
23
|
+
using Process.times.
|
24
24
|
|
25
25
|
== SYNOPSIS
|
26
26
|
|
@@ -46,6 +46,7 @@ Use a Hitimes::Timer to calculate statistics about an iterative operation
|
|
46
46
|
puts timer.max
|
47
47
|
puts timer.min
|
48
48
|
puts timer.stddev
|
49
|
+
puts timer.rate
|
49
50
|
|
50
51
|
|
51
52
|
== CHANGES
|
data/ext/extconf.rb
CHANGED
@@ -2,7 +2,7 @@ require 'rbconfig'
|
|
2
2
|
require 'mkmf'
|
3
3
|
|
4
4
|
if Config::CONFIG['host_os'] =~ /darwin/ then
|
5
|
-
$CFLAGS += " -DUSE_INSTANT_OSX=1"
|
5
|
+
$CFLAGS += " -DUSE_INSTANT_OSX=1 -Wall"
|
6
6
|
$LDFLAGS += " -framework CoreServices"
|
7
7
|
elsif Config::CONFIG['host_os'] =~ /win32/ or Config::CONFIG['host_os'] =~ /mingw/ then
|
8
8
|
$CFLAGS += " -DUSE_INSTANT_WINDOWS=1"
|
data/ext/hitimes_ext.c
CHANGED
data/ext/hitimes_stats.c
CHANGED
@@ -217,7 +217,7 @@ VALUE hitimes_stats_stddev ( VALUE self )
|
|
217
217
|
* end
|
218
218
|
* end
|
219
219
|
*
|
220
|
-
* %w[ count min max mean sum stddev ].each do |m|
|
220
|
+
* %w[ count min max mean sum stddev rate ].each do |m|
|
221
221
|
* puts "#{m.rjust(6)} : #{s.send( m ) }"
|
222
222
|
* end
|
223
223
|
*/
|
@@ -230,11 +230,12 @@ void Init_hitimes_stats()
|
|
230
230
|
rb_define_alloc_func( cH_Stats, hitimes_stats_alloc );
|
231
231
|
|
232
232
|
rb_define_method( cH_Stats, "update", hitimes_stats_update, 1 ); /* in hitimes_stats.c */
|
233
|
-
|
234
|
-
rb_define_method( cH_Stats, "
|
233
|
+
|
234
|
+
rb_define_method( cH_Stats, "count", hitimes_stats_count, 0 ); /* in hitimes_stats.c */
|
235
235
|
rb_define_method( cH_Stats, "max", hitimes_stats_max, 0 ); /* in hitimes_stats.c */
|
236
|
+
rb_define_method( cH_Stats, "mean", hitimes_stats_mean, 0 ); /* in hitimes_stats.c */
|
236
237
|
rb_define_method( cH_Stats, "min", hitimes_stats_min, 0 ); /* in hitimes_stats.c */
|
237
|
-
rb_define_method( cH_Stats, "
|
238
|
+
rb_define_method( cH_Stats, "rate", hitimes_stats_rate, 0 ); /* in hitimes_stats.c */
|
238
239
|
rb_define_method( cH_Stats, "sum", hitimes_stats_sum, 0 ); /* in hitimes_stats.c */
|
239
240
|
rb_define_method( cH_Stats, "stddev", hitimes_stats_stddev, 0 ); /* in hitimes_stats.c */
|
240
241
|
}
|
data/ext/rbconfig-mingw.rb
CHANGED
@@ -111,7 +111,7 @@ module Config
|
|
111
111
|
CONFIG["STRIP"] = "strip"
|
112
112
|
CONFIG["EXTSTATIC"] = ""
|
113
113
|
CONFIG["setup"] = "Setup"
|
114
|
-
CONFIG["MINIRUBY"] = "ruby -I/
|
114
|
+
CONFIG["MINIRUBY"] = "ruby -I#{ENV['HOME']}/pkgs/ruby-1.8.6-p114 -rfake"
|
115
115
|
CONFIG["PREP"] = "fake.rb"
|
116
116
|
CONFIG["RUNRUBY"] = "$(MINIRUBY) -I`cd $(srcdir)/lib; pwd`"
|
117
117
|
CONFIG["EXTOUT"] = ".ext"
|
@@ -142,7 +142,7 @@ module Config
|
|
142
142
|
CONFIG["arch"] = "i386-mingw32"
|
143
143
|
CONFIG["sitearch"] = "i386-msvcrt"
|
144
144
|
CONFIG["sitedir"] = "$(prefix)/lib/ruby/site_ruby"
|
145
|
-
CONFIG["configure_args"] = " '--host=i386-mingw32' '--target=i386-mingw32' '--build=i686-darwin9.2.2' '--prefix
|
145
|
+
CONFIG["configure_args"] = " '--host=i386-mingw32' '--target=i386-mingw32' '--build=i686-darwin9.2.2' '--prefix=#{ENV['HOME']}/ruby-mingw32' 'build_alias=i686-darwin9.2.2' 'host_alias=i386-mingw32' 'target_alias=i386-mingw32'"
|
146
146
|
CONFIG["NROFF"] = "/usr/bin/nroff"
|
147
147
|
CONFIG["MANTYPE"] = "doc"
|
148
148
|
CONFIG["ruby_version"] = "$(MAJOR).$(MINOR)"
|
data/ext/rbconfig.rb
CHANGED
@@ -111,7 +111,7 @@ module Config
|
|
111
111
|
CONFIG["STRIP"] = "strip"
|
112
112
|
CONFIG["EXTSTATIC"] = ""
|
113
113
|
CONFIG["setup"] = "Setup"
|
114
|
-
CONFIG["MINIRUBY"] = "ruby -I/
|
114
|
+
CONFIG["MINIRUBY"] = "ruby -I#{ENV['HOME']}/pkgs/ruby-1.8.6-p114 -rfake"
|
115
115
|
CONFIG["PREP"] = "fake.rb"
|
116
116
|
CONFIG["RUNRUBY"] = "$(MINIRUBY) -I`cd $(srcdir)/lib; pwd`"
|
117
117
|
CONFIG["EXTOUT"] = ".ext"
|
@@ -142,7 +142,7 @@ module Config
|
|
142
142
|
CONFIG["arch"] = "i386-mingw32"
|
143
143
|
CONFIG["sitearch"] = "i386-msvcrt"
|
144
144
|
CONFIG["sitedir"] = "$(prefix)/lib/ruby/site_ruby"
|
145
|
-
CONFIG["configure_args"] = " '--host=i386-mingw32' '--target=i386-mingw32' '--build=i686-darwin9.2.2' '--prefix
|
145
|
+
CONFIG["configure_args"] = " '--host=i386-mingw32' '--target=i386-mingw32' '--build=i686-darwin9.2.2' '--prefix=#{ENV['HOME']}/ruby-mingw32' 'build_alias=i686-darwin9.2.2' 'host_alias=i386-mingw32' 'target_alias=i386-mingw32'"
|
146
146
|
CONFIG["NROFF"] = "/usr/bin/nroff"
|
147
147
|
CONFIG["MANTYPE"] = "doc"
|
148
148
|
CONFIG["ruby_version"] = "$(MAJOR).$(MINOR)"
|
data/gemspec.rb
CHANGED
@@ -22,7 +22,6 @@ Hitimes::GEM_SPEC = Gem::Specification.new do |spec|
|
|
22
22
|
# add dependencies here
|
23
23
|
spec.add_dependency("rake", ">= 0.8.1")
|
24
24
|
spec.add_dependency("configuration", ">= 0.0.5")
|
25
|
-
spec.add_dependency("mkrf", ">= 0.2.3")
|
26
25
|
|
27
26
|
if ext_conf = Configuration.for_if_exist?("extension") then
|
28
27
|
spec.extensions << ext_conf.configs
|
data/lib/hitimes.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'hitimes'
|
2
|
+
require 'thread'
|
3
|
+
|
4
|
+
module Hitimes
|
5
|
+
class MutexedStats < Stats
|
6
|
+
def initialize
|
7
|
+
@mutex = Mutex.new
|
8
|
+
end
|
9
|
+
|
10
|
+
# call-seq:
|
11
|
+
# mutex_stat.update( val ) -> nil
|
12
|
+
#
|
13
|
+
# Update the running stats with the new value in a threadsafe manner.
|
14
|
+
#
|
15
|
+
def update( value )
|
16
|
+
@mutex.synchronize do
|
17
|
+
super( value )
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Hitimes
|
2
|
+
class Stats
|
3
|
+
# A list of the available stats
|
4
|
+
STATS = %w[ count max mean min rate stddev sum ]
|
5
|
+
|
6
|
+
#
|
7
|
+
# call-seq:
|
8
|
+
# stat.to_hash -> Hash
|
9
|
+
# stat.to_hash( %w[ count max mean ]) -> Hash
|
10
|
+
#
|
11
|
+
# return a hash of the stats. By default this returns a hash of all stats
|
12
|
+
# but passing in an array of items will limit the stats returned to only
|
13
|
+
# those in the Array.
|
14
|
+
#
|
15
|
+
# If passed in an empty array or nil to to_hash then STATS is assumed to be
|
16
|
+
# the list of stats to return in the hash.
|
17
|
+
#
|
18
|
+
def to_hash( *args )
|
19
|
+
h = {}
|
20
|
+
args = [ args ].flatten
|
21
|
+
args = STATS if args.empty?
|
22
|
+
args.each do |meth|
|
23
|
+
h[meth] = self.send( meth )
|
24
|
+
end
|
25
|
+
return h
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
data/lib/hitimes/version.rb
CHANGED
data/lib/hitimes_ext.so
CHANGED
Binary file
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
|
2
|
+
|
3
|
+
require 'hitimes_ext'
|
4
|
+
require 'hitimes/mutexed_stats'
|
5
|
+
|
6
|
+
describe Hitimes::MutexedStats do
|
7
|
+
before( :each ) do
|
8
|
+
@threads = 5
|
9
|
+
@iters = 10_000
|
10
|
+
@final_value = @threads * @iters
|
11
|
+
end
|
12
|
+
|
13
|
+
def run_with_scissors( stats, threads, iters )
|
14
|
+
spool = []
|
15
|
+
threads.times do |t|
|
16
|
+
spool << Thread.new { iters.times{ stats.update( 1 ) } }
|
17
|
+
end
|
18
|
+
spool.each { |t| t.join }
|
19
|
+
return stats
|
20
|
+
end
|
21
|
+
|
22
|
+
it "is unsafe normally" do
|
23
|
+
pending "not for MRI -- not interruptable in this C extension" do
|
24
|
+
stats = run_with_scissors( ::Hitimes::Stats.new, @threads, @iters )
|
25
|
+
stats.count.should_not == @final_value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "has a threadsafe update" do
|
30
|
+
stats = run_with_scissors( ::Hitimes::MutexedStats.new, @threads, @iters )
|
31
|
+
stats.count.should == @final_value
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/spec/stats_spec.rb
CHANGED
@@ -15,6 +15,7 @@ describe Hitimes::Stats do
|
|
15
15
|
@stats.min.should == 0.0
|
16
16
|
@stats.max.should == 0.0
|
17
17
|
@stats.sum.should == 0.0
|
18
|
+
@stats.rate.should == 0.0
|
18
19
|
end
|
19
20
|
|
20
21
|
it "calculates the mean correctly" do
|
@@ -45,4 +46,27 @@ describe Hitimes::Stats do
|
|
45
46
|
@full_stats.stddev.should == 1.0
|
46
47
|
end
|
47
48
|
|
49
|
+
describe "#to_hash " do
|
50
|
+
it "converts to a Hash" do
|
51
|
+
h = @full_stats.to_hash
|
52
|
+
h.size.should == ::Hitimes::Stats::STATS.size
|
53
|
+
h.keys.sort.should == ::Hitimes::Stats::STATS
|
54
|
+
end
|
55
|
+
|
56
|
+
it "converts to a limited Hash if given arguments" do
|
57
|
+
h = @full_stats.to_hash( "min", "max", "mean" )
|
58
|
+
h.size.should == 3
|
59
|
+
h.keys.sort.should == %w[ max mean min ]
|
60
|
+
|
61
|
+
h = @full_stats.to_hash( %w[ count rate ] )
|
62
|
+
h.size.should == 2
|
63
|
+
h.keys.sort.should == %w[ count rate ]
|
64
|
+
end
|
65
|
+
|
66
|
+
it "raises NoMethodError if an invalid stat is used" do
|
67
|
+
lambda { @full_stats.to_hash( "wibble" ) }.should raise_error( NoMethodError )
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
48
72
|
end
|
data/tasks/config.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hitimes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: x86-mswin32-60
|
6
6
|
authors:
|
7
7
|
- Jeremy Hinegardner
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-12-20 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -32,17 +32,7 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 0.0.5
|
34
34
|
version:
|
35
|
-
|
36
|
-
name: mkrf
|
37
|
-
type: :runtime
|
38
|
-
version_requirement:
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
40
|
-
requirements:
|
41
|
-
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: 0.2.3
|
44
|
-
version:
|
45
|
-
description: Hitimes is a fast, high resolution timer library for recording performance metrics. It uses the appropriate C method calls for each system to get the highest granularity time increments possible. It currently supports any system with the POSIX call clock_gettime() and OSX. Windows is in the works. Using Hitimes can be faster than using a series of Time.new calls, and it will have a much higher granularity. It is definitely faster than using Process.times.
|
35
|
+
description: Hitimes is a fast, high resolution timer library for recording performance metrics. It uses the appropriate C method calls for each system to get the highest granularity time increments possible. It currently supports any system with the POSIX call clock_gettime(), Mac OS X and Windows. Using Hitimes can be faster than using a series of Time.new calls, and it will have a much higher granularity. It is definitely faster than using Process.times.
|
46
36
|
email: jeremy@copiousfreetime.org
|
47
37
|
executables: []
|
48
38
|
|
@@ -52,7 +42,9 @@ extra_rdoc_files:
|
|
52
42
|
- README
|
53
43
|
- HISTORY
|
54
44
|
- LICENSE
|
45
|
+
- lib/hitimes/mutexed_stats.rb
|
55
46
|
- lib/hitimes/paths.rb
|
47
|
+
- lib/hitimes/stats.rb
|
56
48
|
- lib/hitimes/timer.rb
|
57
49
|
- lib/hitimes/version.rb
|
58
50
|
- lib/hitimes.rb
|
@@ -76,11 +68,14 @@ files:
|
|
76
68
|
- ext/extconf.rb
|
77
69
|
- ext/rbconfig-mingw.rb
|
78
70
|
- ext/rbconfig.rb
|
71
|
+
- lib/hitimes/mutexed_stats.rb
|
79
72
|
- lib/hitimes/paths.rb
|
73
|
+
- lib/hitimes/stats.rb
|
80
74
|
- lib/hitimes/timer.rb
|
81
75
|
- lib/hitimes/version.rb
|
82
76
|
- lib/hitimes.rb
|
83
77
|
- spec/interval_spec.rb
|
78
|
+
- spec/mutex_stats_spec.rb
|
84
79
|
- spec/paths_spec.rb
|
85
80
|
- spec/spec_helper.rb
|
86
81
|
- spec/stats_spec.rb
|
@@ -126,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
121
|
requirements: []
|
127
122
|
|
128
123
|
rubyforge_project: copiousfreetime
|
129
|
-
rubygems_version: 1.
|
124
|
+
rubygems_version: 1.3.1
|
130
125
|
signing_key:
|
131
126
|
specification_version: 2
|
132
127
|
summary: Hitimes is a fast, high resolution timer library for recording performance metrics
|