hitimes 1.1.1-x86-mingw32 → 1.2.2-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/.travis.yml +10 -0
  2. data/CONTRIBUTING.md +45 -0
  3. data/{HISTORY → HISTORY.md} +42 -18
  4. data/LICENSE +11 -8
  5. data/Manifest.txt +45 -0
  6. data/README.md +163 -0
  7. data/Rakefile +23 -62
  8. data/ext/hitimes/c/extconf.rb +24 -0
  9. data/ext/hitimes/{hitimes_ext.c → c/hitimes.c} +1 -1
  10. data/ext/hitimes/{hitimes_instant_clock_gettime.c → c/hitimes_instant_clock_gettime.c} +0 -0
  11. data/ext/hitimes/c/hitimes_instant_osx.c +45 -0
  12. data/ext/hitimes/{hitimes_instant_windows.c → c/hitimes_instant_windows.c} +0 -0
  13. data/ext/hitimes/{hitimes_interval.c → c/hitimes_interval.c} +15 -7
  14. data/ext/hitimes/{hitimes_interval.h → c/hitimes_interval.h} +5 -5
  15. data/ext/hitimes/{hitimes_stats.c → c/hitimes_stats.c} +0 -0
  16. data/ext/hitimes/{hitimes_stats.h → c/hitimes_stats.h} +0 -0
  17. data/ext/hitimes/java/src/hitimes/Hitimes.java +54 -0
  18. data/ext/hitimes/java/src/hitimes/HitimesInterval.java +181 -0
  19. data/ext/hitimes/java/src/hitimes/HitimesService.java +16 -0
  20. data/ext/hitimes/java/src/hitimes/HitimesStats.java +112 -0
  21. data/lib/hitimes.rb +15 -5
  22. data/lib/hitimes/1.9/hitimes.so +0 -0
  23. data/lib/hitimes/2.0/hitimes.so +0 -0
  24. data/lib/hitimes/2.1/hitimes.so +0 -0
  25. data/lib/hitimes/version.rb +1 -50
  26. data/spec/hitimes_spec.rb +14 -0
  27. data/spec/interval_spec.rb +40 -37
  28. data/spec/metric_spec.rb +8 -10
  29. data/spec/mutex_stats_spec.rb +10 -8
  30. data/spec/paths_spec.rb +3 -5
  31. data/spec/spec_helper.rb +9 -3
  32. data/spec/stats_spec.rb +28 -30
  33. data/spec/timed_metric_spec.rb +42 -42
  34. data/spec/timed_value_metric_spec.rb +54 -55
  35. data/spec/value_metric_spec.rb +26 -28
  36. data/spec/version_spec.rb +4 -30
  37. data/tasks/default.rake +242 -0
  38. data/tasks/extension.rake +31 -101
  39. data/tasks/this.rb +206 -0
  40. metadata +158 -145
  41. data/README +0 -135
  42. data/ext/hitimes/extconf.rb +0 -17
  43. data/ext/hitimes/hitimes_instant_osx.c +0 -16
  44. data/gemspec.rb +0 -64
  45. data/lib/hitimes/1.8/hitimes_ext.so +0 -0
  46. data/lib/hitimes/1.9/hitimes_ext.so +0 -0
  47. data/tasks/announce.rake +0 -42
  48. data/tasks/config.rb +0 -109
  49. data/tasks/distribution.rake +0 -93
  50. data/tasks/documentation.rake +0 -32
  51. data/tasks/rspec.rake +0 -33
  52. data/tasks/rubyforge.rake +0 -55
  53. data/tasks/utils.rb +0 -80
@@ -0,0 +1,112 @@
1
+ package hitimes;
2
+
3
+ import org.jruby.Ruby;
4
+ import org.jruby.RubyClass;
5
+ import org.jruby.RubyObject;
6
+
7
+ import org.jruby.RubyNumeric;
8
+ import org.jruby.runtime.builtin.IRubyObject;
9
+ import org.jruby.runtime.ObjectAllocator;
10
+
11
+ import org.jruby.anno.JRubyMethod;
12
+ import org.jruby.anno.JRubyClass;
13
+
14
+ @JRubyClass( name = "Hitimes::Stats" )
15
+ public class HitimesStats extends RubyObject {
16
+
17
+ private double min = 0.0;
18
+ private double max = 0.0;
19
+ private double sum = 0.0;
20
+ private double sumsq = 0.0;
21
+ private long count = 0;
22
+
23
+ public static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
24
+ public IRubyObject allocate(Ruby runtime, RubyClass klass) {
25
+ return new HitimesStats( runtime, klass );
26
+ }
27
+ };
28
+
29
+ public HitimesStats( Ruby runtime, RubyClass klass ) {
30
+ super( runtime, klass );
31
+ }
32
+
33
+ @JRubyMethod( name = "update", required = 1, argTypes = RubyNumeric.class )
34
+ public IRubyObject update( IRubyObject val ) {
35
+ double v = RubyNumeric.num2dbl( val );
36
+
37
+ if ( 0 == this.count ) {
38
+ this.min = this.max = v;
39
+ } else {
40
+ this.min = ( v < this.min ) ? v : this.min;
41
+ this.max = ( v > this.max ) ? v : this.max;
42
+ }
43
+
44
+ this.count += 1;
45
+ this.sum += v;
46
+ this.sumsq += (v * v);
47
+
48
+ return val;
49
+ }
50
+
51
+ @JRubyMethod( name = "mean" )
52
+ public IRubyObject mean() {
53
+ double mean = 0.0;
54
+
55
+ if ( this.count > 0 ) {
56
+ mean = this.sum / this.count;
57
+ }
58
+
59
+ return getRuntime().newFloat( mean );
60
+ }
61
+
62
+
63
+ @JRubyMethod( name = "rate" )
64
+ public IRubyObject rate() {
65
+ double rate = 0.0;
66
+
67
+ if ( this.sum > 0.0 ) {
68
+ rate = this.count / this.sum ;
69
+ }
70
+
71
+ return getRuntime().newFloat( rate );
72
+ }
73
+
74
+ @JRubyMethod( name = "stddev" )
75
+ public IRubyObject stddev() {
76
+ double stddev = 0.0;
77
+
78
+ if ( this.count > 1 ) {
79
+ double sq_sum = this.sum * this.sum;
80
+ stddev = Math.sqrt( ( this.sumsq - ( sq_sum / this.count ) ) / ( this.count - 1 ) );
81
+ }
82
+ return getRuntime().newFloat( stddev );
83
+ }
84
+
85
+
86
+ @JRubyMethod( name = "min" )
87
+ public IRubyObject min() {
88
+ return getRuntime().newFloat( this.min );
89
+ }
90
+
91
+ @JRubyMethod( name = "max" )
92
+ public IRubyObject max() {
93
+ return getRuntime().newFloat( this.max );
94
+ }
95
+
96
+ @JRubyMethod( name = "sum" )
97
+ public IRubyObject sum() {
98
+ return getRuntime().newFloat( this.sum );
99
+ }
100
+
101
+ @JRubyMethod( name = "sumsq" )
102
+ public IRubyObject sumsq() {
103
+ return getRuntime().newFloat( this.sumsq );
104
+ }
105
+
106
+ @JRubyMethod( name = "count" )
107
+ public IRubyObject count() {
108
+ return getRuntime().newFixnum( this.count );
109
+ }
110
+ }
111
+
112
+
@@ -15,16 +15,26 @@ module Hitimes
15
15
  # Base class of all errors in Hitimes
16
16
  #
17
17
  class Error < ::StandardError; end
18
+
19
+ # Hitimes.measure { } -> Float
20
+ #
21
+ # Times the execution of the block, returning the number of seconds it took
22
+ def self.measure(&block)
23
+ Hitimes::Interval.measure(&block)
24
+ end
18
25
  end
19
26
  require 'hitimes/paths'
20
27
  require 'hitimes/version'
21
28
 
22
- if RUBY_PLATFORM == "java" then
29
+ # Load the binary extension, try loading one for the specific version of ruby
30
+ # and if that fails, then fall back to one in the top of the library.
31
+ # this is the method recommended by rake-compiler
32
+ begin
33
+ # this will be for windows
34
+ require "hitimes/#{RUBY_VERSION.sub(/\.\d$/,'')}/hitimes"
35
+ rescue LoadError
36
+ # everyone else.
23
37
  require 'hitimes/hitimes'
24
- else
25
- # use a version subdirectory for extensions, initially to support windows, but
26
- # why make a special case. It doesn't hurt anyone to have an extra subdir.
27
- require "hitimes/#{RUBY_VERSION.sub(/\.\d$/,'')}/hitimes_ext"
28
38
  end
29
39
 
30
40
  require 'hitimes/stats'
@@ -4,54 +4,5 @@
4
4
  #++
5
5
 
6
6
  module Hitimes
7
- #
8
- # module containing all the version information about Hitimes
9
- #
10
- module Version
11
-
12
- # Major version number
13
- MAJOR = 1
14
-
15
- # Minor version number
16
- MINOR = 1
17
-
18
- # Build number
19
- BUILD = 1
20
-
21
- #
22
- # :call-seq:
23
- # Version.to_a -> [ MAJOR, MINOR, BUILD ]
24
- #
25
- # Return the version as an array of Integers
26
- #
27
- def self.to_a
28
- [MAJOR, MINOR, BUILD]
29
- end
30
-
31
- #
32
- # :call-seq:
33
- # Version.to_s -> "MAJOR.MINOR.BUILD"
34
- #
35
- # Return the version as a String with dotted notation
36
- #
37
- def self.to_s
38
- to_a.join(".")
39
- end
40
-
41
- #
42
- # :call-seq:
43
- # Version.to_hash -> { :major => ..., :minor => ..., :build => ... }
44
- #
45
- # Return the version as a Hash
46
- #
47
- def self.to_hash
48
- { :major => MAJOR, :minor => MINOR, :build => BUILD }
49
- end
50
-
51
- # The Version in MAJOR.MINOR.BUILD dotted notation
52
- STRING = Version.to_s
53
- end
54
-
55
- # The Version in MAJOR.MINOR.BUILD dotted notation
56
- VERSION = Version.to_s
7
+ VERSION = "1.2.2"
57
8
  end
@@ -0,0 +1,14 @@
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
+ end
@@ -1,53 +1,56 @@
1
- require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
2
-
3
- require 'hitimes'
1
+ require "spec_helper"
4
2
 
5
3
  describe Hitimes::Interval do
6
- it "has a 0 duration when newly created" do
7
- i = Hitimes::Interval.new
8
- i.duration == 0.0
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/ )
9
12
  end
10
13
 
11
14
  it "knows if it has been started" do
12
15
  i = Hitimes::Interval.new
13
- i.should_not be_started
16
+ i.started?.must_equal false
14
17
 
15
18
  i.start
16
- i.should be_started
19
+ i.started?.must_equal true
17
20
  end
18
21
 
19
22
  it "knows if it has been stopped" do
20
23
  i = Hitimes::Interval.new
21
24
  i.start
22
- i.should_not be_stopped
25
+ i.stopped?.must_equal false
23
26
  i.stop
24
- i.should be_stopped
27
+ i.stopped?.must_equal true
25
28
  end
26
29
 
27
30
  it "knows if it is currently running" do
28
31
  i = Hitimes::Interval.new
29
- i.should_not be_running
32
+ i.running?.must_equal false
30
33
  i.start
31
- i.should be_running
34
+ i.running?.must_equal true
32
35
  i.stop
33
- i.should_not be_running
36
+ i.running?.must_equal false
34
37
  end
35
38
 
36
39
  it "can time a block of code" do
37
40
  d = Hitimes::Interval.measure do
38
41
  sleep 0.2
39
42
  end
40
- d.should be_close(0.2, 0.02)
43
+ d.must_be_close_to(0.2, 0.002)
41
44
  end
42
45
 
43
46
  it "raises an error if measure is called with no block" do
44
- lambda{ Hitimes::Interval.measure }.should raise_error( Hitimes::Error )
47
+ lambda{ Hitimes::Interval.measure }.must_raise( Hitimes::Error, /\ANo block given to Interval.measure\Z/ )
45
48
  end
46
49
 
47
50
  it "creates an interval via #now" do
48
51
  i = Hitimes::Interval.now
49
- i.should be_started
50
- i.should_not be_stopped
52
+ i.started?.must_equal true
53
+ i.stopped?.must_equal false
51
54
  end
52
55
 
53
56
  it "calling duration multiple times returns successivly grater durations" do
@@ -55,33 +58,33 @@ describe Hitimes::Interval do
55
58
  i.start
56
59
  y = i.duration
57
60
  z = i.duration
58
- z.should > y
61
+ z.must_be :>, y
59
62
  end
60
63
 
61
64
  it "calling start multiple times on has no effect after the first call" do
62
65
  i = Hitimes::Interval.new
63
- i.start.should == true
66
+ i.start.must_equal true
64
67
  x = i.start_instant
65
- i.start_instant.should > 0
66
- i.start.should == false
67
- x.should == i.start_instant
68
+ i.start_instant.must_be :>, 0
69
+ i.start.must_equal false
70
+ x.must_equal i.start_instant
68
71
  end
69
72
 
70
73
  it "returns the duration on the first call to stop" do
71
74
  i = Hitimes::Interval.now
72
75
  d = i.stop
73
- d.should be_instance_of( Float )
76
+ d.must_be_instance_of( Float )
74
77
  end
75
78
 
76
79
  it "calling stop multiple times on has no effect after the first call" do
77
80
  i = Hitimes::Interval.new
78
- i.start.should == true
81
+ i.start.must_equal true
79
82
  i.stop
80
83
 
81
84
  x = i.stop_instant
82
- i.stop_instant.should > 0
83
- i.stop.should == false
84
- x.should == i.stop_instant
85
+ i.stop_instant.must_be :>, 0
86
+ i.stop.must_equal false
87
+ x.must_equal i.stop_instant
85
88
 
86
89
  end
87
90
 
@@ -90,26 +93,26 @@ describe Hitimes::Interval do
90
93
  i.start
91
94
  x = i.stop
92
95
  y = i.duration
93
- i.stop.should == false
96
+ i.stop.must_equal false
94
97
 
95
98
  z = i.duration
96
99
 
97
- x.should == y
98
- x.should == z
100
+ x.must_equal y
101
+ x.must_equal z
99
102
 
100
- y.should == z
103
+ y.must_equal z
101
104
  end
102
105
 
103
106
  it "can return how much time has elapsed from the start without stopping the interval" do
104
107
  i = Hitimes::Interval.new
105
108
  i.start
106
109
  x = i.duration_so_far
107
- i.should be_running
110
+ i.running?.must_equal true
108
111
  y = i.duration_so_far
109
112
  i.stop
110
- x.should < y
111
- x.should < i.duration
112
- y.should < i.duration
113
+ x.must_be :<, y
114
+ x.must_be :<, i.duration
115
+ y.must_be :<, i.duration
113
116
  end
114
117
 
115
118
  describe "#split" do
@@ -118,14 +121,14 @@ describe Hitimes::Interval do
118
121
  i = Hitimes::Interval.new
119
122
  i.start
120
123
  i2 = i.split
121
- i.object_id.should_not == i2.object_id
124
+ i.object_id.wont_equal i2.object_id
122
125
  end
123
126
 
124
127
  it "with the stop instant equivialent to the previous Interval's start instant" do
125
128
  i = Hitimes::Interval.new
126
129
  i.start
127
130
  i2 = i.split
128
- i.stop_instant.should == i2.start_instant
131
+ i.stop_instant.must_equal i2.start_instant
129
132
  end
130
133
  end
131
134
 
@@ -1,6 +1,4 @@
1
- require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
2
-
3
- require 'hitimes/metric'
1
+ require "spec_helper"
4
2
 
5
3
  describe Hitimes::Metric do
6
4
  before( :each ) do
@@ -8,22 +6,22 @@ describe Hitimes::Metric do
8
6
  end
9
7
 
10
8
  it 'has a name' do
11
- @metric.name.should == "testing"
9
+ @metric.name.must_equal "testing"
12
10
  end
13
11
 
14
12
  it "has associated data from initialization" do
15
13
  m = Hitimes::Metric.new( "more-data", 'foo' => 'bar', 'this' => 'that' )
16
- m.additional_data['foo'].should == 'bar'
17
- m.additional_data['this'].should == 'that'
14
+ m.additional_data['foo'].must_equal 'bar'
15
+ m.additional_data['this'].must_equal 'that'
18
16
 
19
17
  m = Hitimes::Metric.new( "more-data", { 'foo' => 'bar', 'this' => 'that' } )
20
- m.additional_data['foo'].should == 'bar'
21
- m.additional_data['this'].should == 'that'
18
+ m.additional_data['foo'].must_equal 'bar'
19
+ m.additional_data['this'].must_equal 'that'
22
20
  end
23
21
 
24
22
  it "initially has no sampling times" do
25
- @metric.sampling_start_time.should == nil
26
- @metric.sampling_stop_time.should == nil
23
+ @metric.sampling_start_time.must_be_nil
24
+ @metric.sampling_stop_time.must_be_nil
27
25
  end
28
26
  end
29
27
 
@@ -1,7 +1,4 @@
1
- require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
2
-
3
- require 'hitimes'
4
- require 'hitimes/mutexed_stats'
1
+ require 'spec_helper'
5
2
 
6
3
  describe Hitimes::MutexedStats do
7
4
  before( :each ) do
@@ -19,16 +16,21 @@ describe Hitimes::MutexedStats do
19
16
  return stats
20
17
  end
21
18
 
22
- it "is unsafe normally" do
23
- pending "not for MRI -- not interruptable in this C extension" do
19
+ if (not defined? RUBY_ENGINE) or (RUBY_ENGINE == "ruby") then
20
+ it "Hitimes::Stats is threadsafe" do
21
+ stats = run_with_scissors( ::Hitimes::Stats.new, @threads, @iters )
22
+ stats.count.must_equal @final_value
23
+ end
24
+ else
25
+ it "Hitimes::Stats is not threadsafe" do
24
26
  stats = run_with_scissors( ::Hitimes::Stats.new, @threads, @iters )
25
- stats.count.should_not == @final_value
27
+ stats.count.wont_equal @final_value
26
28
  end
27
29
  end
28
30
 
29
31
  it "has a threadsafe update" do
30
32
  stats = run_with_scissors( ::Hitimes::MutexedStats.new, @threads, @iters )
31
- stats.count.should == @final_value
33
+ stats.count.must_equal @final_value
32
34
  end
33
35
 
34
36
  end