hitimes 0.3.0-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +21 -0
- data/LICENSE +19 -0
- data/README +79 -0
- data/Rakefile +63 -0
- data/examples/benchmarks.rb +86 -0
- data/examples/stats.rb +29 -0
- data/ext/extconf.rb +15 -0
- data/ext/hitimes_ext.c +20 -0
- data/ext/hitimes_instant_clock_gettime.c +20 -0
- data/ext/hitimes_instant_osx.c +16 -0
- data/ext/hitimes_instant_windows.c +27 -0
- data/ext/hitimes_interval.c +340 -0
- data/ext/hitimes_interval.h +73 -0
- data/ext/hitimes_stats.c +241 -0
- data/ext/hitimes_stats.h +30 -0
- data/ext/rbconfig-mingw.rb +178 -0
- data/ext/rbconfig.rb +178 -0
- data/gemspec.rb +55 -0
- data/lib/hitimes.rb +21 -0
- data/lib/hitimes/paths.rb +54 -0
- data/lib/hitimes/timer.rb +223 -0
- data/lib/hitimes/version.rb +42 -0
- data/lib/hitimes_ext.so +0 -0
- data/spec/interval_spec.rb +115 -0
- data/spec/paths_spec.rb +14 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/stats_spec.rb +48 -0
- data/spec/timer_spec.rb +105 -0
- data/spec/version_spec.rb +27 -0
- data/tasks/announce.rake +39 -0
- data/tasks/config.rb +107 -0
- data/tasks/distribution.rake +53 -0
- data/tasks/documentation.rake +33 -0
- data/tasks/extension.rake +64 -0
- data/tasks/rspec.rake +31 -0
- data/tasks/rubyforge.rake +52 -0
- data/tasks/utils.rb +80 -0
- metadata +134 -0
@@ -0,0 +1,42 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2008 Jeremy Hinegardner
|
3
|
+
# All rights reserved. See LICENSE and/or COPYING for details
|
4
|
+
#++
|
5
|
+
|
6
|
+
module Hitimes
|
7
|
+
#
|
8
|
+
# module containing all the version information about Hitimes
|
9
|
+
#
|
10
|
+
module Version
|
11
|
+
|
12
|
+
MAJOR = 0
|
13
|
+
MINOR = 3
|
14
|
+
BUILD = 0
|
15
|
+
|
16
|
+
#
|
17
|
+
# :call-seq:
|
18
|
+
# Version.to_a -> [ MAJOR, MINOR, BUILD ]
|
19
|
+
#
|
20
|
+
# Return the version as an array of Integers
|
21
|
+
#
|
22
|
+
def to_a
|
23
|
+
[MAJOR, MINOR, BUILD]
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# :call-seq:
|
28
|
+
# Version.to_s -> MAJOR.MINOR.BUILD
|
29
|
+
#
|
30
|
+
# Return the version as a String with dotted notation
|
31
|
+
#
|
32
|
+
def to_s
|
33
|
+
to_a.join(".")
|
34
|
+
end
|
35
|
+
|
36
|
+
module_function :to_a
|
37
|
+
module_function :to_s
|
38
|
+
|
39
|
+
STRING = Version.to_s
|
40
|
+
end
|
41
|
+
VERSION = Version.to_s
|
42
|
+
end
|
data/lib/hitimes_ext.so
ADDED
Binary file
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
|
2
|
+
|
3
|
+
require 'hitimes_ext'
|
4
|
+
|
5
|
+
describe Hitimes::Interval do
|
6
|
+
it "has a 0 duration when newly created" do
|
7
|
+
i = Hitimes::Interval.new
|
8
|
+
i.duration == 0.0
|
9
|
+
end
|
10
|
+
|
11
|
+
it "knows if it has been started" do
|
12
|
+
i = Hitimes::Interval.new
|
13
|
+
i.should_not be_started
|
14
|
+
|
15
|
+
i.start
|
16
|
+
i.should be_started
|
17
|
+
end
|
18
|
+
|
19
|
+
it "knows if it has been stopped" do
|
20
|
+
i = Hitimes::Interval.new
|
21
|
+
i.start
|
22
|
+
i.should_not be_stopped
|
23
|
+
i.stop
|
24
|
+
i.should be_stopped
|
25
|
+
end
|
26
|
+
|
27
|
+
it "knows if it is currently running" do
|
28
|
+
i = Hitimes::Interval.new
|
29
|
+
i.should_not be_running
|
30
|
+
i.start
|
31
|
+
i.should be_running
|
32
|
+
i.stop
|
33
|
+
i.should_not be_running
|
34
|
+
end
|
35
|
+
|
36
|
+
it "can time a block of code" do
|
37
|
+
d = Hitimes::Interval.measure do
|
38
|
+
sleep 0.2
|
39
|
+
end
|
40
|
+
d.should be_close(0.2, 0.01)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "raises an error if measure is called with no block" do
|
44
|
+
lambda{ Hitimes::Interval.measure }.should raise_error( Hitimes::Error )
|
45
|
+
end
|
46
|
+
|
47
|
+
it "creates an interval via #now" do
|
48
|
+
i = Hitimes::Interval.now
|
49
|
+
i.should be_started
|
50
|
+
i.should_not be_stopped
|
51
|
+
end
|
52
|
+
|
53
|
+
it "calling duration multiple times returns successivly grater durations" do
|
54
|
+
i = Hitimes::Interval.new
|
55
|
+
i.start
|
56
|
+
y = i.duration
|
57
|
+
z = i.duration
|
58
|
+
z.should > y
|
59
|
+
end
|
60
|
+
|
61
|
+
it "calling start multiple times on has no effect after the first call" do
|
62
|
+
i = Hitimes::Interval.new
|
63
|
+
i.start.should == true
|
64
|
+
x = i.start_instant
|
65
|
+
i.start_instant.should > 0
|
66
|
+
i.start.should == false
|
67
|
+
x.should == i.start_instant
|
68
|
+
end
|
69
|
+
|
70
|
+
it "returns the duration on the first call to stop" do
|
71
|
+
i = Hitimes::Interval.now
|
72
|
+
d = i.stop
|
73
|
+
d.should be_instance_of( Float )
|
74
|
+
end
|
75
|
+
|
76
|
+
it "calling stop multiple times on has no effect after the first call" do
|
77
|
+
i = Hitimes::Interval.new
|
78
|
+
i.start.should == true
|
79
|
+
i.stop
|
80
|
+
|
81
|
+
x = i.stop_instant
|
82
|
+
i.stop_instant.should > 0
|
83
|
+
i.stop.should == false
|
84
|
+
x.should == i.stop_instant
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
it "only calculates duration once after stop is called" do
|
89
|
+
i = Hitimes::Interval.new
|
90
|
+
i.start
|
91
|
+
i.stop
|
92
|
+
x = i.duration
|
93
|
+
y = i.duration
|
94
|
+
x.object_id.should == y.object_id
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "#split" do
|
98
|
+
|
99
|
+
it "creates a new Interval object" do
|
100
|
+
i = Hitimes::Interval.new
|
101
|
+
i.start
|
102
|
+
i2 = i.split
|
103
|
+
i.object_id.should_not == i2.object_id
|
104
|
+
end
|
105
|
+
|
106
|
+
it "with the stop instant equivialent to the previous Interval's start instant" do
|
107
|
+
i = Hitimes::Interval.new
|
108
|
+
i.start
|
109
|
+
i2 = i.split
|
110
|
+
i.stop_instant.should == i2.start_instant
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
data/spec/paths_spec.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
|
2
|
+
|
3
|
+
require 'hitimes/paths'
|
4
|
+
|
5
|
+
describe Hitimes::Paths do
|
6
|
+
it "can access the root dir of the project" do
|
7
|
+
Hitimes::Paths.root_dir.should == File.expand_path( File.join( File.dirname( __FILE__ ), ".." ) ) + ::File::SEPARATOR
|
8
|
+
end
|
9
|
+
|
10
|
+
it "can access the lib path of the project" do
|
11
|
+
Hitimes::Paths.lib_path.should == File.expand_path( File.join( File.dirname( __FILE__ ), "..", "lib" ) ) + ::File::SEPARATOR
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/spec/stats_spec.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
|
2
|
+
|
3
|
+
require 'hitimes_ext'
|
4
|
+
|
5
|
+
describe Hitimes::Stats do
|
6
|
+
before( :each ) do
|
7
|
+
@stats = Hitimes::Stats.new
|
8
|
+
@full_stats = Hitimes::Stats.new
|
9
|
+
|
10
|
+
[ 1, 2, 3].each { |i| @full_stats.update( i ) }
|
11
|
+
end
|
12
|
+
|
13
|
+
it "is initialized with 0 values" do
|
14
|
+
@stats.count.should == 0
|
15
|
+
@stats.min.should == 0.0
|
16
|
+
@stats.max.should == 0.0
|
17
|
+
@stats.sum.should == 0.0
|
18
|
+
end
|
19
|
+
|
20
|
+
it "calculates the mean correctly" do
|
21
|
+
@full_stats.mean.should == 2.0
|
22
|
+
end
|
23
|
+
|
24
|
+
it "calculates the rate correctly" do
|
25
|
+
@full_stats.rate.should == 0.5
|
26
|
+
end
|
27
|
+
|
28
|
+
it "tracks the maximum value" do
|
29
|
+
@full_stats.max.should == 3.0
|
30
|
+
end
|
31
|
+
|
32
|
+
it "tracks the minimum value" do
|
33
|
+
@full_stats.min.should == 1.0
|
34
|
+
end
|
35
|
+
|
36
|
+
it "tracks the count" do
|
37
|
+
@full_stats.count.should == 3
|
38
|
+
end
|
39
|
+
|
40
|
+
it "tracks the sum" do
|
41
|
+
@full_stats.sum.should == 6.0
|
42
|
+
end
|
43
|
+
|
44
|
+
it "calculates the standard deviation" do
|
45
|
+
@full_stats.stddev.should == 1.0
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
data/spec/timer_spec.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
|
2
|
+
|
3
|
+
require 'hitimes/timer'
|
4
|
+
|
5
|
+
describe Hitimes::Timer do
|
6
|
+
|
7
|
+
it "knows if it is running or not" do
|
8
|
+
t = Hitimes::Timer.new
|
9
|
+
t.should_not be_running
|
10
|
+
t.start
|
11
|
+
t.should be_running
|
12
|
+
t.stop
|
13
|
+
t.should_not be_running
|
14
|
+
end
|
15
|
+
|
16
|
+
it "#split returns the last duration and the timer is still running" do
|
17
|
+
t = Hitimes::Timer.now
|
18
|
+
d = t.split
|
19
|
+
t.should be_running
|
20
|
+
d.should > 0
|
21
|
+
t.count.should == 1
|
22
|
+
t.duration.should == d
|
23
|
+
end
|
24
|
+
|
25
|
+
it "#stop returns false if called more than once in a row" do
|
26
|
+
t = Hitimes::Timer.new
|
27
|
+
t.start
|
28
|
+
t.stop.should > 0
|
29
|
+
t.stop.should == false
|
30
|
+
end
|
31
|
+
|
32
|
+
it "does not count a currently running interval as an interval in calculations" do
|
33
|
+
t = Hitimes::Timer.new
|
34
|
+
t.start
|
35
|
+
t.count.should == 0
|
36
|
+
t.split
|
37
|
+
t.count.should == 1
|
38
|
+
end
|
39
|
+
|
40
|
+
it "#split called on a stopped timer does nothing" do
|
41
|
+
t = Hitimes::Timer.new
|
42
|
+
t.start
|
43
|
+
t.stop
|
44
|
+
t.split.should == false
|
45
|
+
end
|
46
|
+
|
47
|
+
it "calculates the mean of the durations" do
|
48
|
+
t = Hitimes::Timer.new
|
49
|
+
2.times { t.start ; sleep 0.05 ; t.stop }
|
50
|
+
t.mean.should > 0.04
|
51
|
+
end
|
52
|
+
|
53
|
+
it "calculates the rate of the counts " do
|
54
|
+
t = Hitimes::Timer.new
|
55
|
+
5.times { t.start ; sleep 0.05 ; t.stop }
|
56
|
+
t.rate.should > 19.0
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
it "calculates the stddev of the durations" do
|
61
|
+
t = Hitimes::Timer.new
|
62
|
+
2.times { t.start ; sleep 0.05 ; t.stop }
|
63
|
+
t.stddev.should > 0.0
|
64
|
+
end
|
65
|
+
|
66
|
+
it "returns 0.0 for stddev if there is no data" do
|
67
|
+
t = Hitimes::Timer.new
|
68
|
+
t.stddev.should == 0.0
|
69
|
+
end
|
70
|
+
|
71
|
+
it "retuns 0.0 for mean if there is no data" do
|
72
|
+
Hitimes::Timer.new.mean.should == 0.0
|
73
|
+
end
|
74
|
+
|
75
|
+
it "keeps track of the min value" do
|
76
|
+
t = Hitimes::Timer.new
|
77
|
+
2.times { t.start ; sleep 0.05 ; t.stop }
|
78
|
+
t.min.should > 0
|
79
|
+
end
|
80
|
+
|
81
|
+
it "keeps track of the max value" do
|
82
|
+
t = Hitimes::Timer.new
|
83
|
+
2.times { t.start ; sleep 0.05 ; t.stop }
|
84
|
+
t.max.should > 0
|
85
|
+
end
|
86
|
+
|
87
|
+
it "can create an already running timer" do
|
88
|
+
t = Hitimes::Timer.now
|
89
|
+
t.should be_running
|
90
|
+
end
|
91
|
+
|
92
|
+
it "can measure a block of code's execution time" do
|
93
|
+
dur = Hitimes::Timer.measure { sleep 0.05 }
|
94
|
+
dur.should > 0.025
|
95
|
+
end
|
96
|
+
|
97
|
+
it "can measuer a block of code from an instance" do
|
98
|
+
t = Hitimes::Timer.new
|
99
|
+
3.times { t.measure { sleep 0.05 } }
|
100
|
+
t.duration.should > 0.14
|
101
|
+
t.count.should == 3
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper" ) )
|
2
|
+
|
3
|
+
describe "Hitimes::Version" do
|
4
|
+
it "should have a major numbers that is >= 0" do
|
5
|
+
Hitimes::Version::MAJOR.should >= 0
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should have a minor number that is >= 0" do
|
9
|
+
Hitimes::Version::MINOR.should >= 0
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should have a tiny number that is >= 0" do
|
13
|
+
Hitimes::Version::BUILD.should >= 0
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have an array representation" do
|
17
|
+
Hitimes::Version.to_a.should have(3).items
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have a string representation" do
|
21
|
+
Hitimes::Version.to_s.should match(/\d+\.\d+\.\d+/)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should be accessable as a constant" do
|
25
|
+
Hitimes::VERSION.should match(/\d+\.\d+\.\d+/)
|
26
|
+
end
|
27
|
+
end
|
data/tasks/announce.rake
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'tasks/config'
|
2
|
+
#-------------------------------------------------------------------------------
|
3
|
+
# announcement methods
|
4
|
+
#-------------------------------------------------------------------------------
|
5
|
+
|
6
|
+
proj_config = Configuration.for('project')
|
7
|
+
namespace :announce do
|
8
|
+
desc "create email for ruby-talk"
|
9
|
+
task :email do
|
10
|
+
info = Utils.announcement
|
11
|
+
|
12
|
+
File.open("email.txt", "w") do |mail|
|
13
|
+
mail.puts "From: #{proj_config.author} <#{proj_config.email}>"
|
14
|
+
mail.puts "To: ruby-talk@ruby-lang.org"
|
15
|
+
mail.puts "Date: #{Time.now.rfc2822}"
|
16
|
+
mail.puts "Subject: [ANN] #{info[:subject]}"
|
17
|
+
mail.puts
|
18
|
+
mail.puts info[:title]
|
19
|
+
mail.puts
|
20
|
+
mail.puts " gem install #{Hitimes::GEM_SPEC.name}"
|
21
|
+
mail.puts
|
22
|
+
mail.puts info[:urls]
|
23
|
+
mail.puts
|
24
|
+
mail.puts info[:description]
|
25
|
+
mail.puts
|
26
|
+
mail.puts "{{ Release notes for Version #{Hitimes::VERSION} }}"
|
27
|
+
mail.puts
|
28
|
+
mail.puts info[:release_notes]
|
29
|
+
mail.puts
|
30
|
+
end
|
31
|
+
puts "Created the following as email.txt:"
|
32
|
+
puts "-" * 72
|
33
|
+
puts File.read("email.txt")
|
34
|
+
puts "-" * 72
|
35
|
+
end
|
36
|
+
|
37
|
+
CLOBBER << "email.txt"
|
38
|
+
end
|
39
|
+
|
data/tasks/config.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'configuration'
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'tasks/utils'
|
5
|
+
|
6
|
+
#-----------------------------------------------------------------------
|
7
|
+
# General project configuration
|
8
|
+
#-----------------------------------------------------------------------
|
9
|
+
Configuration.for('project') {
|
10
|
+
name "hitimes"
|
11
|
+
version Hitimes::Version.to_s
|
12
|
+
author "Jeremy Hinegardner"
|
13
|
+
email "jeremy at copiousfreetime dot org"
|
14
|
+
homepage "http://copiousfreetime.rubyforge.org/hitimes/"
|
15
|
+
description Utils.section_of("README", "description")
|
16
|
+
summary description.split(".").first
|
17
|
+
history "HISTORY"
|
18
|
+
license FileList["LICENSE"]
|
19
|
+
readme "README"
|
20
|
+
}
|
21
|
+
|
22
|
+
#-----------------------------------------------------------------------
|
23
|
+
# Packaging
|
24
|
+
#-----------------------------------------------------------------------
|
25
|
+
Configuration.for('packaging') {
|
26
|
+
# files in the project
|
27
|
+
proj_conf = Configuration.for('project')
|
28
|
+
files {
|
29
|
+
bin FileList["bin/*"]
|
30
|
+
ext FileList["ext/*.{c,h,rb}"]
|
31
|
+
examples FileList["examples/*.rb"]
|
32
|
+
lib FileList["lib/**/*.rb"]
|
33
|
+
test FileList["spec/**/*.rb", "test/**/*.rb"]
|
34
|
+
data FileList["data/**/*"]
|
35
|
+
tasks FileList["tasks/**/*.r{ake,b}"]
|
36
|
+
rdoc FileList[proj_conf.readme, proj_conf.history,
|
37
|
+
proj_conf.license] + lib + FileList["ext/*.c"]
|
38
|
+
all bin + examples + ext + lib + test + data + rdoc + tasks + FileList["Rakefile"]
|
39
|
+
}
|
40
|
+
|
41
|
+
# ways to package the results
|
42
|
+
formats {
|
43
|
+
tgz true
|
44
|
+
zip true
|
45
|
+
gem Configuration::Table.has_key?('gem')
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
#-----------------------------------------------------------------------
|
50
|
+
# Gem packaging
|
51
|
+
#-----------------------------------------------------------------------
|
52
|
+
Configuration.for("gem") {
|
53
|
+
spec "gemspec.rb"
|
54
|
+
Configuration.for('packaging').files.all << spec
|
55
|
+
}
|
56
|
+
|
57
|
+
#-----------------------------------------------------------------------
|
58
|
+
# Testing
|
59
|
+
# - change mode to 'testunit' to use unit testing
|
60
|
+
#-----------------------------------------------------------------------
|
61
|
+
Configuration.for('test') {
|
62
|
+
mode "spec"
|
63
|
+
files Configuration.for("packaging").files.test
|
64
|
+
options %w[ --format specdoc --color ]
|
65
|
+
ruby_opts %w[ ]
|
66
|
+
}
|
67
|
+
|
68
|
+
#-----------------------------------------------------------------------
|
69
|
+
# Rcov
|
70
|
+
#-----------------------------------------------------------------------
|
71
|
+
Configuration.for('rcov') {
|
72
|
+
output_dir "coverage"
|
73
|
+
libs %w[ lib ]
|
74
|
+
rcov_opts %w[ --html ]
|
75
|
+
ruby_opts %w[ ]
|
76
|
+
test_files Configuration.for('packaging').files.test
|
77
|
+
}
|
78
|
+
|
79
|
+
#-----------------------------------------------------------------------
|
80
|
+
# Rdoc
|
81
|
+
#-----------------------------------------------------------------------
|
82
|
+
Configuration.for('rdoc') {
|
83
|
+
files Configuration.for('packaging').files.rdoc
|
84
|
+
main_page files.first
|
85
|
+
title Configuration.for('project').name
|
86
|
+
options %w[ --line-numbers --inline-source ]#-f darkfish ]
|
87
|
+
output_dir "doc"
|
88
|
+
}
|
89
|
+
|
90
|
+
#-----------------------------------------------------------------------
|
91
|
+
# Extension
|
92
|
+
#-----------------------------------------------------------------------
|
93
|
+
Configuration.for('extension') {
|
94
|
+
configs Configuration.for('packaging').files.ext.find_all { |x| %w[ mkrf_conf.rb extconf.rb ].include?(File.basename(x)) }
|
95
|
+
}
|
96
|
+
|
97
|
+
#-----------------------------------------------------------------------
|
98
|
+
# Rubyforge
|
99
|
+
#-----------------------------------------------------------------------
|
100
|
+
Configuration.for('rubyforge') {
|
101
|
+
project "copiousfreetime"
|
102
|
+
user "jjh"
|
103
|
+
host "rubyforge.org"
|
104
|
+
rdoc_location "#{user}@#{host}:/var/www/gforge-projects/#{project}/hitimes"
|
105
|
+
}
|
106
|
+
|
107
|
+
|