hitimes 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
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 performance
15
- metrics. It uses the appropriate C method calls for each system to get the
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() and OSX.
19
- Windows is in the works.
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 it will
22
- have a much higher granularity. It is definitely faster than using
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
@@ -1,4 +1,5 @@
1
1
  #include <ruby.h>
2
+ #include "hitimes_interval.h"
2
3
 
3
4
  /* Module and Classes */
4
5
  VALUE mH; /* module Hitimes */
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
- rb_define_method( cH_Stats, "mean", hitimes_stats_mean, 0 ); /* in hitimes_stats.c */
234
- rb_define_method( cH_Stats, "rate", hitimes_stats_rate, 0 ); /* in hitimes_stats.c */
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, "count", hitimes_stats_count, 0 ); /* in hitimes_stats.c */
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
  }
@@ -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/Users/jeremy/pkgs/ruby-1.8.6-p114 -rfake"
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=/Users/jeremy/ruby-mingw32' 'build_alias=i686-darwin9.2.2' 'host_alias=i386-mingw32' 'target_alias=i386-mingw32'"
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/Users/jeremy/pkgs/ruby-1.8.6-p114 -rfake"
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=/Users/jeremy/ruby-mingw32' 'build_alias=i686-darwin9.2.2' 'host_alias=i386-mingw32' 'target_alias=i386-mingw32'"
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
@@ -18,4 +18,7 @@ module Hitimes
18
18
  end
19
19
  require 'hitimes/paths'
20
20
  require 'hitimes/version'
21
+ require 'hitimes/stats'
22
+ require 'hitimes/mutexed_stats'
21
23
  require 'hitimes/timer'
24
+
@@ -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
@@ -10,7 +10,7 @@ module Hitimes
10
10
  module Version
11
11
 
12
12
  MAJOR = 0
13
- MINOR = 3
13
+ MINOR = 4
14
14
  BUILD = 0
15
15
 
16
16
  #
@@ -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
@@ -42,7 +42,7 @@ Configuration.for('packaging') {
42
42
  formats {
43
43
  tgz true
44
44
  zip true
45
- gem Configuration::Table.has_key?('gem')
45
+ rubygem Configuration::Table.has_key?('gem')
46
46
  }
47
47
  }
48
48
 
data/tasks/rubyforge.rake CHANGED
@@ -11,7 +11,7 @@ if rf_conf = Configuration.for_if_exist?("rubyforge") then
11
11
 
12
12
  namespace :dist do
13
13
  desc "Release files to rubyforge"
14
- task :rubyforge => [:clean, :package] do
14
+ task :rubyforge => [:clean, :package, :package_win] do
15
15
 
16
16
  rubyforge = RubyForge.new
17
17
 
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.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
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-10-11 00:00:00 -06:00
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
- - !ruby/object:Gem::Dependency
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
@@ -125,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
120
  requirements: []
126
121
 
127
122
  rubyforge_project: copiousfreetime
128
- rubygems_version: 1.2.0
123
+ rubygems_version: 1.3.1
129
124
  signing_key:
130
125
  specification_version: 2
131
126
  summary: Hitimes is a fast, high resolution timer library for recording performance metrics