hitimes 1.0.3-x86-mswin32-60 → 1.2.2-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.
Files changed (60) hide show
  1. data/.travis.yml +10 -0
  2. data/CONTRIBUTING.md +45 -0
  3. data/HISTORY.md +97 -0
  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 +18 -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/metric.rb +6 -0
  26. data/lib/hitimes/mutexed_stats.rb +5 -1
  27. data/lib/hitimes/stats.rb +5 -1
  28. data/lib/hitimes/timed_metric.rb +1 -2
  29. data/lib/hitimes/timed_value_metric.rb +0 -2
  30. data/lib/hitimes/value_metric.rb +2 -3
  31. data/lib/hitimes/version.rb +1 -50
  32. data/spec/hitimes_spec.rb +14 -0
  33. data/spec/interval_spec.rb +40 -37
  34. data/spec/metric_spec.rb +8 -10
  35. data/spec/mutex_stats_spec.rb +10 -8
  36. data/spec/paths_spec.rb +3 -5
  37. data/spec/spec_helper.rb +9 -4
  38. data/spec/stats_spec.rb +28 -30
  39. data/spec/timed_metric_spec.rb +44 -44
  40. data/spec/timed_value_metric_spec.rb +54 -55
  41. data/spec/value_metric_spec.rb +28 -30
  42. data/spec/version_spec.rb +4 -30
  43. data/tasks/default.rake +254 -0
  44. data/tasks/extension.rake +29 -73
  45. data/tasks/this.rb +200 -0
  46. metadata +173 -105
  47. data/HISTORY +0 -55
  48. data/README +0 -134
  49. data/ext/hitimes/extconf.rb +0 -21
  50. data/ext/hitimes/hitimes_instant_osx.c +0 -16
  51. data/gemspec.rb +0 -57
  52. data/lib/hitimes/1.8/hitimes_ext.so +0 -0
  53. data/lib/hitimes/1.9/hitimes_ext.so +0 -0
  54. data/tasks/announce.rake +0 -39
  55. data/tasks/config.rb +0 -108
  56. data/tasks/distribution.rake +0 -74
  57. data/tasks/documentation.rake +0 -32
  58. data/tasks/rspec.rake +0 -31
  59. data/tasks/rubyforge.rake +0 -55
  60. 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,18 +15,31 @@ 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
- # support for fat binaries on windows
23
- if RUBY_PLATFORM =~ /(mswin|mingw)/i
24
- require "hitimes/#{RUBY_VERSION.sub(/\.\d$/,'')}/hitimes_ext"
25
- else
26
- require 'hitimes/hitimes_ext'
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.
37
+ require 'hitimes/hitimes'
27
38
  end
39
+
28
40
  require 'hitimes/stats'
29
41
  require 'hitimes/mutexed_stats'
42
+
30
43
  require 'hitimes/metric'
31
44
  require 'hitimes/value_metric'
32
45
  require 'hitimes/timed_metric'
@@ -1,3 +1,9 @@
1
+
2
+ #--
3
+ # Copyright (c) 2008, 2009 Jeremy Hinegardner
4
+ # All rights reserved. See LICENSE and/or COPYING for details.
5
+ #++
6
+
1
7
  module Hitimes
2
8
  #
3
9
  # Metric hold the common meta information for all derived metric classes
@@ -1,4 +1,8 @@
1
- require 'hitimes'
1
+ #--
2
+ # Copyright (c) 2008, 2009 Jeremy Hinegardner
3
+ # All rights reserved. See LICENSE and/or COPYING for details.
4
+ #++
5
+
2
6
  require 'thread'
3
7
 
4
8
  module Hitimes
@@ -1,4 +1,8 @@
1
- require 'hitimes'
1
+ #--
2
+ # Copyright (c) 2008, 2009 Jeremy Hinegardner
3
+ # All rights reserved. See LICENSE and/or COPYING for details.
4
+ #++
5
+
2
6
  require 'stringio'
3
7
  module Hitimes
4
8
  class Stats
@@ -3,7 +3,6 @@
3
3
  # All rights reserved. See LICENSE and/or COPYING for details.
4
4
  #++
5
5
 
6
- require 'hitimes'
7
6
  require 'forwardable'
8
7
  module Hitimes
9
8
  #
@@ -171,7 +170,7 @@ module Hitimes
171
170
 
172
171
  # forward appropriate calls directly to the stats object
173
172
  extend Forwardable
174
- def_delegators :@stats, :count, :sum, :max, :mean, :min, :rate, :stddev, :sum, :sumsq
173
+ def_delegators :@stats, :count, :max, :mean, :min, :rate, :stddev, :sum, :sumsq
175
174
  alias :duration :sum
176
175
  end
177
176
  end
@@ -3,8 +3,6 @@
3
3
  # All rights reserved. See LICENSE and/or COPYING for details.
4
4
  #++
5
5
 
6
- require 'hitimes'
7
-
8
6
  module Hitimes
9
7
  #
10
8
  # A TimedValueMetric holds the metrics on how long it takes to do a batch of something.
@@ -4,7 +4,6 @@
4
4
  #++
5
5
 
6
6
  require 'forwardable'
7
- require 'hitimes'
8
7
  module Hitimes
9
8
  #
10
9
  # A ValueMetric holds the data from measuring a single value over a period of
@@ -67,6 +66,6 @@ module Hitimes
67
66
 
68
67
  # forward appropriate calls directly to the stats object
69
68
  extend Forwardable
70
- def_delegators :@stats, :count, :sum, :max, :mean, :min, :stddev, :sum, :sumsq
71
- end
69
+ def_delegators :@stats, :count, :max, :mean, :min, :stddev, :sum, :sumsq
70
+ end
72
71
  end
@@ -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 = 0
17
-
18
- # Build number
19
- BUILD = 3
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/hitimes_ext'
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.01)
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