should_be_faster 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,13 @@
1
1
  require 'benchmark'
2
- require 'spec'
3
- require 'spec/matchers'
4
- require 'spec/matchers/be'
2
+ require 'rspec'
3
+ require 'rspec/matchers'
4
+ require 'rspec/matchers/be'
5
5
 
6
6
  def _benchmark(code, iter)
7
7
  Benchmark.measure { iter.times { code.call } }
8
8
  end
9
9
 
10
- module Spec
10
+ module RSpec
11
11
  module Matchers
12
12
  class BenchmarkComparison
13
13
  def initialize(rhs_code, options={})
@@ -64,8 +64,8 @@ module Spec
64
64
  end
65
65
 
66
66
  module BeFasterThan
67
- def times
68
- @factor = @args[0]
67
+ def times(*args)
68
+ @factor = args[0]
69
69
  self
70
70
  end
71
71
 
@@ -75,7 +75,7 @@ module Spec
75
75
  Matcher.new(:faster_than) do
76
76
  options[:faster] = true
77
77
  options[:matcher] = self
78
- Spec::Matchers::BenchmarkComparison.new(rhs_code, options).benchmark_comparison
78
+ RSpec::Matchers::BenchmarkComparison.new(rhs_code, options).benchmark_comparison
79
79
  end
80
80
  end
81
81
 
@@ -85,7 +85,7 @@ module Spec
85
85
  Matcher.new(:slower_than) do
86
86
  options[:faster] = false
87
87
  options[:matcher] = self
88
- Spec::Matchers::BenchmarkComparison.new(rhs_code, options).benchmark_comparison
88
+ RSpec::Matchers::BenchmarkComparison.new(rhs_code, options).benchmark_comparison
89
89
  end
90
90
  end
91
91
  end
@@ -93,20 +93,21 @@ module Spec
93
93
  end
94
94
  end
95
95
 
96
- Spec::Matchers::BePredicate.send(:include, Spec::Matchers::BeFasterThan)
97
- Spec::Matchers::BeSameAs.send(:include, Spec::Matchers::BeFasterThan)
96
+ RSpec::Matchers::BePredicate.send(:include, RSpec::Matchers::BeFasterThan)
97
+ RSpec::Matchers::BeComparedTo.send(:include, RSpec::Matchers::BeFasterThan)
98
+ RSpec::Matchers::Matcher.send(:include, RSpec::Matchers::BeFasterThan)
98
99
 
99
- Spec::Matchers.define(:be_faster_than) do |rhs_code, options|
100
+ RSpec::Matchers.define(:be_faster_than) do |rhs_code, options|
100
101
  options ||= {}
101
102
  options[:matcher] = self
102
103
  options[:faster] = true
103
- Spec::Matchers::BenchmarkComparison.new(rhs_code, options).benchmark_comparison
104
+ RSpec::Matchers::BenchmarkComparison.new(rhs_code, options).benchmark_comparison
104
105
  end
105
106
 
106
- Spec::Matchers.define(:be_slower_than) do |rhs_code, options|
107
+ RSpec::Matchers.define(:be_slower_than) do |rhs_code, options|
107
108
  options ||= {}
108
109
  options[:matcher] = self
109
110
  options[:faster] = false
110
- Spec::Matchers::BenchmarkComparison.new(rhs_code, options).benchmark_comparison
111
+ RSpec::Matchers::BenchmarkComparison.new(rhs_code, options).benchmark_comparison
111
112
  end
112
113
 
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: should_be_faster
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 27
5
+ prerelease:
5
6
  segments:
6
7
  - 0
8
+ - 1
7
9
  - 0
8
- - 3
9
- version: 0.0.3
10
+ version: 0.1.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - David Turnbull
@@ -14,21 +15,9 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-05-06 00:00:00 +10:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: rspec
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- version: "0"
30
- type: :runtime
31
- version_requirements: *id001
18
+ date: 2011-05-16 00:00:00 Z
19
+ dependencies: []
20
+
32
21
  description:
33
22
  email: dsturnbull@gmail.com
34
23
  executables: []
@@ -40,35 +29,38 @@ extra_rdoc_files:
40
29
  files:
41
30
  - lib/should_be_faster.rb
42
31
  - README
43
- has_rdoc: true
44
32
  homepage: http://github.com/dsturnbull/should_be_faster
45
33
  licenses: []
46
34
 
47
35
  post_install_message:
48
- rdoc_options:
49
- - --charset=UTF-8
36
+ rdoc_options: []
37
+
50
38
  require_paths:
51
39
  - lib
52
40
  required_ruby_version: !ruby/object:Gem::Requirement
41
+ none: false
53
42
  requirements:
54
43
  - - ">="
55
44
  - !ruby/object:Gem::Version
45
+ hash: 3
56
46
  segments:
57
47
  - 0
58
48
  version: "0"
59
49
  required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
60
51
  requirements:
61
52
  - - ">="
62
53
  - !ruby/object:Gem::Version
54
+ hash: 3
63
55
  segments:
64
56
  - 0
65
57
  version: "0"
66
58
  requirements: []
67
59
 
68
60
  rubyforge_project:
69
- rubygems_version: 1.3.6
61
+ rubygems_version: 1.7.2
70
62
  signing_key:
71
63
  specification_version: 3
72
64
  summary: provides rspec matcher to do simple benchmark tests
73
- test_files:
74
- - spec/should_be_faster_spec.rb
65
+ test_files: []
66
+
@@ -1,122 +0,0 @@
1
- require 'lib/should_be_faster'
2
-
3
- describe 'should_be_faster' do
4
- it 'should default to 100 iterations' do
5
- options = mock('hash')
6
- options.stub!(:[]).and_return(nil)
7
- options.stub!(:[]=)
8
- options.should_receive(:[]=).with(:iterations, 100)
9
- Spec::Matchers::BenchmarkComparison.new(nil, options)
10
- end
11
-
12
- context 'with an options hash' do
13
- it 'should allow you to specify iterations' do
14
- options = mock('hash')
15
- options.stub!(:[])
16
- options.stub!(:[]=)
17
- options.stub!(:[]).with(:iterations).and_return(20)
18
- Spec::Matchers::BenchmarkComparison.new(nil, options)
19
- options[:iterations].should == 20
20
- end
21
-
22
- it 'should allow you to specify factor' do
23
- options = mock('hash')
24
- options.stub!(:[])
25
- options.stub!(:[]=)
26
- options.stub!(:[]).with(:factor).and_return(20)
27
- Spec::Matchers::BenchmarkComparison.new(nil, options)
28
- options[:factor].should == 20
29
- end
30
- end
31
-
32
- context 'when ensuring code is' do
33
- before do
34
- @fast = lambda { [1, 2, 3, 4, 5, 6, 7, 8, 9].sort }
35
- @slow = lambda { 100.times.map { rand } }
36
- end
37
-
38
- context 'faster_than' do
39
- it 'should ensure lhs < rhs' do
40
- @fast.should be_faster_than(@slow)
41
- end
42
-
43
- it 'should ensure lhs < rhs by x times' do
44
- @fast.should be_faster_than(@slow, :factor => 2)
45
- end
46
-
47
- it 'should ensure lhs < rhs by y secs'
48
-
49
- it 'should ensure lhs !> rhs' do
50
- @slow.should_not be_faster_than(@fast)
51
- end
52
-
53
- it 'should ensure lhs !> rhs by x times' do
54
- @slow.should_not be_faster_than(@fast, :factor => 2)
55
- end
56
-
57
- it 'should ensure lhs !> rhs by y secs'
58
- end
59
-
60
- context 'slower_than' do
61
- it 'should ensure lhs > rhs' do
62
- @slow.should be_slower_than(@fast)
63
- end
64
-
65
- it 'should ensure lhs > rhs by x times' do
66
- @slow.should be_slower_than(@fast, :factor => 2)
67
- end
68
-
69
- it 'should ensure lhs > rhs by y secs'
70
-
71
- it 'should ensure lhs !< rhs' do
72
- @fast.should_not be_slower_than(@slow)
73
- end
74
-
75
- it 'should ensure lhs !< rhs by x times' do
76
- @fast.should_not be_slower_than(@slow, :factor => 2)
77
- end
78
-
79
- it 'should ensure lhs !< rhs by y secs'
80
- end
81
-
82
- context 'at_least(x).times.faster_than' do
83
- it 'should ensure lhs < rhs' do
84
- @fast.should be_at_least(2).times.faster_than(@slow)
85
- end
86
-
87
- it 'should ensure lhs !> rhs' do
88
- @slow.should_not be_at_least(2).times.faster_than(@fast)
89
- end
90
- end
91
-
92
- context 'at_least(x).times.slower_than' do
93
- it 'should ensure lhs > rhs' do
94
- @slow.should be_at_least(2).times.slower_than(@fast)
95
- end
96
-
97
- it 'should ensure lhs !< rhs' do
98
- @fast.should_not be_at_least(2).times.slower_than(@slow)
99
- end
100
- end
101
-
102
- context 'x.times.slower_than' do
103
- it 'should ensure lhs > rhs' do
104
- @slow.should be(2).times.slower_than(@fast)
105
- end
106
-
107
- it 'should ensure lhs !< rhs' do
108
- @fast.should_not be(2).times.slower_than(@slow)
109
- end
110
- end
111
-
112
- context 'x.times.faster_than' do
113
- it 'should ensure lhs > rhs' do
114
- @fast.should be(2).times.faster_than(@slow)
115
- end
116
-
117
- it 'should ensure lhs !< rhs' do
118
- @slow.should_not be(2).times.faster_than(@fast)
119
- end
120
- end
121
- end
122
- end