speed 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/Manifest +3 -1
  2. data/README.rdoc +76 -0
  3. data/Rakefile +1 -1
  4. data/lib/speed.rb +10 -17
  5. data/spec/speed.rb +22 -0
  6. data/speed.gemspec +3 -3
  7. metadata +5 -2
data/Manifest CHANGED
@@ -1,4 +1,6 @@
1
+ Manifest
2
+ README.rdoc
1
3
  Rakefile
2
4
  init.rb
3
5
  lib/speed.rb
4
- Manifest
6
+ spec/speed.rb
data/README.rdoc ADDED
@@ -0,0 +1,76 @@
1
+ = Speed
2
+
3
+ Quick and easy timing for ruby methods which can be used to time code in controllers or models for rails
4
+
5
+ == Installation
6
+
7
+ Speed can be installed either as a rails plugin or as a gem.
8
+
9
+ == Basic Usage
10
+
11
+ Speed is extremely easy to use, and super light weight. All you need to do is include Speed into the class or module you require timed methods for, and put your code that you need timed into our timer block, and the results can be viewed with the 'speed' method, which is a hash of all your timers.
12
+
13
+ require 'rubygems'
14
+ require 'speed'
15
+
16
+ module TestSpeed
17
+ include Speed
18
+
19
+ def TimeMe
20
+ timer(:time_me_method) do
21
+ sleep(2)
22
+ end
23
+
24
+ puts speed[:time_me_method] # Will return the speed in seconds
25
+ end
26
+ end
27
+
28
+ Speed also allows you to have multiple timers in timers, so you can break your code into different timed blocks.
29
+
30
+ == Usage in Rails
31
+
32
+ We created this gem to time how long some of our controllers took to render. This is how we use it:
33
+
34
+ class SearchController < ApplicationController
35
+ include Speed
36
+
37
+ def results
38
+ timer(:results) do
39
+ @results = Product.search(params[:keyword])
40
+ end
41
+
42
+ @timer = speed[:results]
43
+ end
44
+ end
45
+
46
+ If you install this gem as a rails plugin, you wont need to 'include Speed' in your controllers or models. This would be done for you.
47
+
48
+
49
+
50
+ Follow me on twitter: http://twitter.com/ryan_za
51
+
52
+ Email: ryan *at* platform45.com
53
+
54
+
55
+ == License
56
+
57
+ Copyright (c) 2009 Platform45
58
+
59
+ Permission is hereby granted, free of charge, to any person obtaining
60
+ a copy of this software and associated documentation files (the
61
+ "Software"), to deal in the Software without restriction, including
62
+ without limitation the rights to use, copy, modify, merge, publish,
63
+ distribute, sublicense, and/or sell copies of the Software, and to
64
+ permit persons to whom the Software is furnished to do so, subject to
65
+ the following conditions:
66
+
67
+ The above copyright notice and this permission notice shall be
68
+ included in all copies or substantial portions of the Software.
69
+
70
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
71
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
72
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
73
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
74
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
75
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
76
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('speed', '0.1.0') do |p|
5
+ Echoe.new('speed', '0.2.0') do |p|
6
6
  p.description = "Quick and easy timing for ruby methods which can be used to time code in controllers or models for rails"
7
7
  p.url = "http://github.com/platform45/speed"
8
8
  p.author = "Platform45"
data/lib/speed.rb CHANGED
@@ -1,21 +1,14 @@
1
1
  module Speed
2
- def self.included(base)
3
- base.extend ClassMethods
2
+ @@results = {}
3
+
4
+ def timer(name)
5
+ start_time = Time.now
6
+ yield
7
+ result = Time.now - start_time
8
+ @@results[name.to_sym] = result
4
9
  end
5
-
6
- module ClassMethods
7
-
8
- @@results = {}
9
-
10
- def timer(name)
11
- start_time = Time.now
12
- yield
13
- result = Time.now - start_time
14
- @@results[name.to_sym] = result
15
- end
16
-
17
- def speed
18
- @@results
19
- end
10
+
11
+ def speed
12
+ @@results
20
13
  end
21
14
  end
data/spec/speed.rb ADDED
@@ -0,0 +1,22 @@
1
+ $:.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'rubygems'
3
+ require 'speed'
4
+
5
+ describe "Speed" do
6
+ before(:each) do
7
+ module Test
8
+ include Speed
9
+ end
10
+
11
+ Test.timer(:test) do
12
+ sleep(1)
13
+ end
14
+ end
15
+ it "Should time the block" do
16
+ Test.speed.should_not be_nil
17
+ end
18
+
19
+ it "should return the timed results in a hash" do
20
+ Test.speed.class.should == Hash
21
+ end
22
+ end
data/speed.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{speed}
5
- s.version = "0.1.0"
5
+ s.version = "0.2.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Platform45"]
9
9
  s.date = %q{2010-01-19}
10
10
  s.description = %q{Quick and easy timing for ruby methods which can be used to time code in controllers or models for rails}
11
11
  s.email = %q{ryan@platform45.com}
12
- s.extra_rdoc_files = ["lib/speed.rb"]
13
- s.files = ["Rakefile", "init.rb", "lib/speed.rb", "Manifest", "speed.gemspec"]
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/speed.rb"]
13
+ s.files = ["Manifest", "README.rdoc", "Rakefile", "init.rb", "lib/speed.rb", "spec/speed.rb", "speed.gemspec"]
14
14
  s.homepage = %q{http://github.com/platform45/speed}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Speed", "--main", "README.rdoc"]
16
16
  s.require_paths = ["lib"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: speed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Platform45
@@ -20,12 +20,15 @@ executables: []
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
+ - README.rdoc
23
24
  - lib/speed.rb
24
25
  files:
26
+ - Manifest
27
+ - README.rdoc
25
28
  - Rakefile
26
29
  - init.rb
27
30
  - lib/speed.rb
28
- - Manifest
31
+ - spec/speed.rb
29
32
  - speed.gemspec
30
33
  has_rdoc: true
31
34
  homepage: http://github.com/platform45/speed