benchmark_unit 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -0,0 +1,2 @@
1
+
2
+ v0.0.1. First release.
data/LICENSE ADDED
@@ -0,0 +1,184 @@
1
+ Academic Free License (AFL) v. 3.0
2
+
3
+ This Academic Free License (the "License") applies to any original work
4
+ of authorship (the "Original Work") whose owner (the "Licensor") has
5
+ placed the following licensing notice adjacent to the copyright notice
6
+ for the Original Work:
7
+
8
+ Licensed under the Academic Free License version 3.0
9
+
10
+ 1) Grant of Copyright License. Licensor grants You a worldwide,
11
+ royalty-free, non-exclusive, sublicensable license, for the duration of
12
+ the copyright, to do the following:
13
+
14
+ a) to reproduce the Original Work in copies, either alone or as part of
15
+ a collective work;
16
+
17
+ b) to translate, adapt, alter, transform, modify, or arrange the
18
+ Original Work, thereby creating derivative works ("Derivative Works")
19
+ based upon the Original Work;
20
+
21
+ c) to distribute or communicate copies of the Original Work and
22
+ Derivative Works to the public, under any license of your choice that
23
+ does not contradict the terms and conditions, including Licensor's
24
+ reserved rights and remedies, in this Academic Free License;
25
+
26
+ d) to perform the Original Work publicly; and
27
+
28
+ e) to display the Original Work publicly.
29
+
30
+ 2) Grant of Patent License. Licensor grants You a worldwide,
31
+ royalty-free, non-exclusive, sublicensable license, under patent claims
32
+ owned or controlled by the Licensor that are embodied in the Original
33
+ Work as furnished by the Licensor, for the duration of the patents, to
34
+ make, use, sell, offer for sale, have made, and import the Original Work
35
+ and Derivative Works.
36
+
37
+ 3) Grant of Source Code License. The term "Source Code" means the
38
+ preferred form of the Original Work for making modifications to it and
39
+ all available documentation describing how to modify the Original Work.
40
+ Licensor agrees to provide a machine-readable copy of the Source Code of
41
+ the Original Work along with each copy of the Original Work that
42
+ Licensor distributes. Licensor reserves the right to satisfy this
43
+ obligation by placing a machine-readable copy of the Source Code in an
44
+ information repository reasonably calculated to permit inexpensive and
45
+ convenient access by You for as long as Licensor continues to distribute
46
+ the Original Work.
47
+
48
+ 4) Exclusions From License Grant. Neither the names of Licensor, nor the
49
+ names of any contributors to the Original Work, nor any of their
50
+ trademarks or service marks, may be used to endorse or promote products
51
+ derived from this Original Work without express prior permission of the
52
+ Licensor. Except as expressly stated herein, nothing in this License
53
+ grants any license to Licensor's trademarks, copyrights, patents, trade
54
+ secrets or any other intellectual property. No patent license is granted
55
+ to make, use, sell, offer for sale, have made, or import embodiments of
56
+ any patent claims other than the licensed claims defined in Section 2.
57
+ No license is granted to the trademarks of Licensor even if such marks
58
+ are included in the Original Work. Nothing in this License shall be
59
+ interpreted to prohibit Licensor from licensing under terms different
60
+ from this License any Original Work that Licensor otherwise would have a
61
+ right to license.
62
+
63
+ 5) External Deployment. The term "External Deployment" means the use,
64
+ distribution, or communication of the Original Work or Derivative Works
65
+ in any way such that the Original Work or Derivative Works may be used
66
+ by anyone other than You, whether those works are distributed or
67
+ communicated to those persons or made available as an application
68
+ intended for use over a network. As an express condition for the grants
69
+ of license hereunder, You must treat any External Deployment by You of
70
+ the Original Work or a Derivative Work as a distribution under section
71
+ 1(c).
72
+
73
+ 6) Attribution Rights. You must retain, in the Source Code of any
74
+ Derivative Works that You create, all copyright, patent, or trademark
75
+ notices from the Source Code of the Original Work, as well as any
76
+ notices of licensing and any descriptive text identified therein as an
77
+ "Attribution Notice." You must cause the Source Code for any Derivative
78
+ Works that You create to carry a prominent Attribution Notice reasonably
79
+ calculated to inform recipients that You have modified the Original
80
+ Work.
81
+
82
+ 7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants
83
+ that the copyright in and to the Original Work and the patent rights
84
+ granted herein by Licensor are owned by the Licensor or are sublicensed
85
+ to You under the terms of this License with the permission of the
86
+ contributor(s) of those copyrights and patent rights. Except as
87
+ expressly stated in the immediately preceding sentence, the Original
88
+ Work is provided under this License on an "AS IS" BASIS and WITHOUT
89
+ WARRANTY, either express or implied, including, without limitation, the
90
+ warranties of non-infringement, merchantability or fitness for a
91
+ particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL
92
+ WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential
93
+ part of this License. No license to the Original Work is granted by this
94
+ License except under this disclaimer.
95
+
96
+ 8) Limitation of Liability. Under no circumstances and under no legal
97
+ theory, whether in tort (including negligence), contract, or otherwise,
98
+ shall the Licensor be liable to anyone for any indirect, special,
99
+ incidental, or consequential damages of any character arising as a
100
+ result of this License or the use of the Original Work including,
101
+ without limitation, damages for loss of goodwill, work stoppage,
102
+ computer failure or malfunction, or any and all other commercial damages
103
+ or losses. This limitation of liability shall not apply to the extent
104
+ applicable law prohibits such limitation.
105
+
106
+ 9) Acceptance and Termination. If, at any time, You expressly assented
107
+ to this License, that assent indicates your clear and irrevocable
108
+ acceptance of this License and all of its terms and conditions. If You
109
+ distribute or communicate copies of the Original Work or a Derivative
110
+ Work, You must make a reasonable effort under the circumstances to
111
+ obtain the express assent of recipients to the terms of this License.
112
+ This License conditions your rights to undertake the activities listed
113
+ in Section 1, including your right to create Derivative Works based upon
114
+ the Original Work, and doing so without honoring these terms and
115
+ conditions is prohibited by copyright law and international treaty.
116
+ Nothing in this License is intended to affect copyright exceptions and
117
+ limitations (including "fair use" or "fair dealing"). This License shall
118
+ terminate immediately and You may no longer exercise any of the rights
119
+ granted to You by this License upon your failure to honor the conditions
120
+ in Section 1(c).
121
+
122
+ 10) Termination for Patent Action. This License shall terminate
123
+ automatically and You may no longer exercise any of the rights granted
124
+ to You by this License as of the date You commence an action, including
125
+ a cross-claim or counterclaim, against Licensor or any licensee alleging
126
+ that the Original Work infringes a patent. This termination provision
127
+ shall not apply for an action alleging patent infringement by
128
+ combinations of the Original Work with other software or hardware.
129
+
130
+ 11) Jurisdiction, Venue and Governing Law. Any action or suit relating
131
+ to this License may be brought only in the courts of a jurisdiction
132
+ wherein the Licensor resides or in which Licensor conducts its primary
133
+ business, and under the laws of that jurisdiction excluding its
134
+ conflict-of-law provisions. The application of the United Nations
135
+ Convention on Contracts for the International Sale of Goods is expressly
136
+ excluded. Any use of the Original Work outside the scope of this License
137
+ or after its termination shall be subject to the requirements and
138
+ penalties of copyright or patent law in the appropriate jurisdiction.
139
+ This section shall survive the termination of this License.
140
+
141
+ 12) Attorneys' Fees. In any action to enforce the terms of this License
142
+ or seeking damages relating thereto, the prevailing party shall be
143
+ entitled to recover its costs and expenses, including, without
144
+ limitation, reasonable attorneys' fees and costs incurred in connection
145
+ with such action, including any appeal of such action. This section
146
+ shall survive the termination of this License.
147
+
148
+ 13) Miscellaneous. If any provision of this License is held to be
149
+ unenforceable, such provision shall be reformed only to the extent
150
+ necessary to make it enforceable.
151
+
152
+ 14) Definition of "You" in This License. "You" throughout this License,
153
+ whether in upper or lower case, means an individual or a legal entity
154
+ exercising rights under, and complying with all of the terms of, this
155
+ License. For legal entities, "You" includes any entity that controls, is
156
+ controlled by, or is under common control with you. For purposes of this
157
+ definition, "control" means (i) the power, direct or indirect, to cause
158
+ the direction or management of such entity, whether by contract or
159
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
160
+ outstanding shares, or (iii) beneficial ownership of such entity.
161
+
162
+ 15) Right to Use. You may use the Original Work in all ways not
163
+ otherwise restricted or conditioned by this License or by law, and
164
+ Licensor promises not to interfere with or be responsible for such uses
165
+ by You.
166
+
167
+ 16) Modification of This License. This License is Copyright (c) 2005
168
+ Lawrence Rosen. Permission is granted to copy, distribute, or
169
+ communicate this License without modification. Nothing in this License
170
+ permits You to modify this License as applied to the Original Work or to
171
+ Derivative Works. However, You may modify the text of this License and
172
+ copy, distribute or communicate your modified version (the "Modified
173
+ License") and apply it to other original works of authorship subject to
174
+ the following conditions: (i) You may not indicate in any way that your
175
+ Modified License is the "Academic Free License" or "AFL" and you may not
176
+ use those names in the name of your Modified License; (ii) You must
177
+ replace the notice specified in the first paragraph above with the
178
+ notice "Licensed under <insert your license name here>" or with a notice
179
+ of your own that is not confusingly similar to the notice in this
180
+ License; and (iii) You may not claim that your original works are open
181
+ source software unless your Modified License has been approved by Open
182
+ Source Initiative (OSI) and You comply with its license review and
183
+ certification process.
184
+
@@ -0,0 +1,9 @@
1
+ CHANGELOG
2
+ lib/benchmark/assertions.rb
3
+ lib/benchmark/float.rb
4
+ lib/benchmark/ruby_seconds.rb
5
+ lib/benchmark/unit.rb
6
+ LICENSE
7
+ Manifest
8
+ README
9
+ test/unit/benchmark_unit_test.rb
data/README ADDED
@@ -0,0 +1,10 @@
1
+
2
+ benchmark_unit
3
+
4
+ Adds machine-independent benchmark assertions to your unit tests.
5
+
6
+ == License
7
+
8
+ Copyright 2007 Cloudburst, LLC. See included LICENSE file.
9
+
10
+ The public certificate for this gem is at http://rubyforge.org/frs/download.php/25331/evan_weaver-original-public_cert.pem.
@@ -0,0 +1,40 @@
1
+
2
+ # Gem::Specification for Benchmark_unit-0.0.1
3
+ # Originally generated by Echoe
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = %q{benchmark_unit}
7
+ s.version = "0.0.1"
8
+
9
+ s.specification_version = 2 if s.respond_to? :specification_version=
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.authors = ["Evan Weaver"]
13
+ s.date = %q{2008-01-08}
14
+ s.description = %q{Adds machine-independent benchmark assertions to your unit tests.}
15
+ s.email = %q{}
16
+ s.files = ["CHANGELOG", "lib/benchmark/assertions.rb", "lib/benchmark/float.rb", "lib/benchmark/ruby_seconds.rb", "lib/benchmark/unit.rb", "LICENSE", "Manifest", "README", "test/unit/benchmark_unit_test.rb", "benchmark_unit.gemspec"]
17
+ s.has_rdoc = true
18
+ s.homepage = %q{http://blog.evanweaver.com/files/doc/fauna/benchmark_unit/}
19
+ s.require_paths = ["lib"]
20
+ s.rubyforge_project = %q{fauna}
21
+ s.rubygems_version = %q{1.0.1}
22
+ s.summary = %q{Adds machine-independent benchmark assertions to your unit tests.}
23
+ s.test_files = ["test/unit/benchmark_unit_test.rb"]
24
+ end
25
+
26
+
27
+ # # Original Rakefile source (requires the Echoe gem):
28
+ #
29
+ #
30
+ # require 'echoe'
31
+ #
32
+ # Echoe.new("benchmark_unit") do |p|
33
+ # p.author = "Evan Weaver"
34
+ # p.project = "fauna"
35
+ # p.summary = "Adds machine-independent benchmark assertions to your unit tests."
36
+ # p.url = "http://blog.evanweaver.com/files/doc/fauna/benchmark_unit/"
37
+ # p.docs_host = 'blog.evanweaver.com:~/www/bax/public/files/doc/'
38
+ # p.require_signed = true
39
+ # p.test_pattern = ["**/test/**/*.rb"]
40
+ # end
@@ -0,0 +1,53 @@
1
+
2
+ require 'test/unit/assertions'
3
+
4
+ module Test
5
+ module Unit
6
+ module Assertions
7
+
8
+ def assert_faster(target = 1/0.0, &block)
9
+ compare_benchmark(target, :faster, &block)
10
+ end
11
+
12
+ def assert_slower(target = 0, &block) # Infinity
13
+ compare_benchmark(target, :slower, &block)
14
+ end
15
+
16
+ private
17
+
18
+ def compare_benchmark(target, operator)
19
+ time, multiplier = 0, 1
20
+
21
+ while (time < 0.01) do
22
+ # STDERR.puts "Multiplier is #{multiplier}"
23
+ time = Benchmark::Unit.measure do
24
+ multiplier.times {yield}
25
+ end
26
+ # STDERR.puts "Time was #{time}"
27
+ multiplier *= 10
28
+ end
29
+
30
+ multiplier /= 10
31
+
32
+ iterations = (Benchmark::Unit::CLOCK_TARGET / time).to_i * multiplier
33
+ iterations = 1 if iterations < 1
34
+
35
+ total = Benchmark::Unit.measure do
36
+ iterations.times do
37
+ yield
38
+ end
39
+ end
40
+
41
+ time = total / iterations
42
+ message = "Time #{time.inspect} expected to be #{operator} than #{target.inspect}."
43
+
44
+ if operator == :faster
45
+ assert((time < target), message)
46
+ elsif operator == :slower
47
+ assert((time > target), message)
48
+ end
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,6 @@
1
+
2
+ class Float
3
+ def to_ruby_seconds
4
+ Benchmark::RubySeconds.new(self)
5
+ end
6
+ end
@@ -0,0 +1,73 @@
1
+
2
+ module Benchmark
3
+ class RubySeconds
4
+
5
+ PRECISION = 0.05
6
+
7
+ attr_accessor :value
8
+
9
+ # Create a RubySeconds object from wall clock seconds.
10
+ def initialize(seconds)
11
+ @value = seconds.to_f / RubySeconds.size
12
+ end
13
+
14
+ # Delegate to the float. Inheriting from Float doesn't work well.
15
+ def method_missing(*args)
16
+ @value.send(*args)
17
+ end
18
+
19
+ def to_s
20
+ @value.to_s
21
+ end
22
+
23
+ class << self
24
+
25
+ # Measure the "standard" Ruby unit of time.
26
+ def measure
27
+ Benchmark.measure do
28
+ 4.times { quanta }
29
+ end.total / 4.0
30
+ end
31
+
32
+ # Approach a stable unit size and memoize it.
33
+ def size
34
+ @size ||= begin
35
+ last, size = 0, measure
36
+ while (size < last or (size - last) / size > PRECISION) do
37
+ last, size = size, measure
38
+ end
39
+ last
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ # Perform some common Ruby operations so we can measure how long they take.
46
+ def quanta
47
+ # Allocate things
48
+ array = [:symbol, "a = 3 if true", 2, Math::PI**2, "large string"*30] * 100
49
+ # Re-assign
50
+ array.flatten!
51
+ # Process things with a closure
52
+ array.each_with_index do |item, index|
53
+ begin
54
+ case index % 4
55
+ when 0: item * 20000
56
+ when 1: item / Math::PI / 2.0
57
+ when 2: "#{item} #{item} #{item}"
58
+ when 3: eval(item) if item =~ /true/
59
+ end
60
+ rescue Object => e
61
+ end
62
+ end
63
+ # Dispatch some methods
64
+ recurse(20)
65
+ end
66
+
67
+ def recurse(i)
68
+ recurse(i - 1) if i > 0
69
+ end
70
+
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,28 @@
1
+
2
+ require 'benchmark'
3
+
4
+ require 'rubygems'
5
+ require 'ruby-debug'; Debugger.start
6
+
7
+ require 'benchmark/ruby_seconds'
8
+ require 'benchmark/assertions'
9
+ require 'benchmark/float'
10
+
11
+ module Benchmark
12
+ module Unit
13
+
14
+ CLOCK_TARGET = 2
15
+
16
+ def self.measure
17
+ RubySeconds.new(
18
+ Benchmark.measure do
19
+ yield
20
+ end.total
21
+ )
22
+ end
23
+
24
+ end
25
+ end
26
+
27
+
28
+
@@ -0,0 +1,33 @@
1
+
2
+ $LOAD_PATH << File.dirname(__FILE__) + "/../../lib"
3
+
4
+ require 'benchmark/unit'
5
+ require 'test/unit'
6
+
7
+ # STDERR.puts "RubySeconds.size is #{Benchmark::RubySeconds.size}"
8
+
9
+ class BenchmarkUnitTest < Test::Unit::TestCase
10
+
11
+ def test_faster
12
+ assert_faster do
13
+ # Do nothing
14
+ end
15
+ assert_faster(3) do
16
+ "string" * 100
17
+ end
18
+ end
19
+
20
+ def test_slower
21
+ assert_slower do
22
+ "string" * 100
23
+ end
24
+ assert_slower(1.1) do
25
+ "string" * 30000000
26
+ end
27
+ end
28
+
29
+ def test_failed_assertion_has_clean_backtrace
30
+ # XXX Todo
31
+ end
32
+
33
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: benchmark_unit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Evan Weaver
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDLjCCAhagAwIBAgIBADANBgkqhkiG9w0BAQUFADA9MQ0wCwYDVQQDDARldmFu
14
+ MRgwFgYKCZImiZPyLGQBGRYIY2xvdWRidXIxEjAQBgoJkiaJk/IsZAEZFgJzdDAe
15
+ Fw0wNzA5MTYxMDMzMDBaFw0wODA5MTUxMDMzMDBaMD0xDTALBgNVBAMMBGV2YW4x
16
+ GDAWBgoJkiaJk/IsZAEZFghjbG91ZGJ1cjESMBAGCgmSJomT8ixkARkWAnN0MIIB
17
+ IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5C0Io89nyApnr+PvbNFge9Vs
18
+ yRWAlGBUEMahpXp28VrrfXZT0rAW7JBo4PlCE3jl4nE4dzE6gAdItSycjTosrw7A
19
+ Ir5+xoyl4Vb35adv56TIQQXvNz+BzlqnkAY5JN0CSBRTQb6mxS3hFyD/h4qgDosj
20
+ R2RFVzHqSxCS8xq4Ny8uzOwOi+Xyu4w67fI5JvnPvMxqrlR1eaIQHmxnf76RzC46
21
+ QO5QhufjAYGGXd960XzbQsQyTDUYJzrvT7AdOfiyZzKQykKt8dEpDn+QPjFTnGnT
22
+ QmgJBX5WJN0lHF2l1sbv3gh4Kn1tZu+kTUqeXY6ShAoDTyvZRiFqQdwh8w2lTQID
23
+ AQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU+WqJz3xQ
24
+ XSea1hRvvHWcIMgeeC4wDQYJKoZIhvcNAQEFBQADggEBAGLZ75jfOEW8Nsl26CTt
25
+ JFrWxQTcQT/UljeefVE3xYr7lc9oQjbqO3FOyued3qW7TaNEtZfSHoYeUSMYbpw1
26
+ XAwocIPuSRFDGM4B+hgQGVDx8PMGiJKom4qLXjO40UZsR7QyN/u869Vj45LURm6h
27
+ MBcPeqCASI+WNprj9+uZa2kmHiitrFqqfMBNlm5IFbn9XeYSta9AHVvs5QQqV2m5
28
+ hIPfLqCyxsn/YgOGvo6iwyQTWyTswamaAC3HRWZxIS1sfn/Ssqa7E7oQMkv5FAXr
29
+ x5rKePfXINf8XTJczkl9OBEYdE9aNdJsJpXD0asLgGVwBICS5Bjohp6mizJcDC1+
30
+ yZ0=
31
+ -----END CERTIFICATE-----
32
+
33
+ date: 2008-01-08 00:00:00 -05:00
34
+ default_executable:
35
+ dependencies: []
36
+
37
+ description: Adds machine-independent benchmark assertions to your unit tests.
38
+ email: ""
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ files:
46
+ - CHANGELOG
47
+ - lib/benchmark/assertions.rb
48
+ - lib/benchmark/float.rb
49
+ - lib/benchmark/ruby_seconds.rb
50
+ - lib/benchmark/unit.rb
51
+ - LICENSE
52
+ - Manifest
53
+ - README
54
+ - test/unit/benchmark_unit_test.rb
55
+ - benchmark_unit.gemspec
56
+ has_rdoc: true
57
+ homepage: http://blog.evanweaver.com/files/doc/fauna/benchmark_unit/
58
+ post_install_message:
59
+ rdoc_options: []
60
+
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ requirements: []
76
+
77
+ rubyforge_project: fauna
78
+ rubygems_version: 1.0.1
79
+ signing_key:
80
+ specification_version: 2
81
+ summary: Adds machine-independent benchmark assertions to your unit tests.
82
+ test_files:
83
+ - test/unit/benchmark_unit_test.rb
@@ -0,0 +1 @@
1
+ N>�"�aĿ/��G��rO��Gl. �J Bt3�hbl�k�g�aS �Q�(m�갳]�d/�����=���;��7_JV͔z����@Bm�Q]P� �(G��.��0�:���N���$`g�S��G �C��6�3]��!�����>�ߵP�7V�LE��ya��|[w�M���*�(��=��� r�:&�n�|'�YgQ��D�?��b��U�) �ڵ4J�[M�Mz�`� ���~�k%@��7"��T �g�