Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add Hitimes.measure

Closed #4
  • Loading branch information...
commit 5dbdf941d1f922f66da1998dbd7d5be6fc32fb92 1 parent e8f29f8
@copiousfreetime authored
View
2  HISTORY.rdoc
@@ -9,6 +9,8 @@
* Make hitimes -w clean
* Fix ambiguity of calling duration on non-started Interval
* Use RbConfig instead of Config (eregon)
+* Added Hitimes.measure
+
== Version 1.1.1 2010-09-04
* Remove the unnecessary dependencies that should be development dependencies
View
7 lib/hitimes.rb
@@ -15,6 +15,13 @@ module Hitimes
# Base class of all errors in Hitimes
#
class Error < ::StandardError; end
+
+ # Hitimes.measure { } -> Float
+ #
+ # Times the execution of the block, returning the number of seconds it took
+ def self.measure(&block)
+ Hitimes::Interval.measure(&block)
+ end
end
require 'hitimes/paths'
require 'hitimes/version'
View
14 spec/hitimes_spec.rb
@@ -0,0 +1,14 @@
+require 'spec_helper'
+
+describe Hitimes do
+ it "can time a block of code" do
+ d = Hitimes.measure do
+ sleep 0.2
+ end
+ d.should be_within(0.02).of(0.2)
+ end
+
+ it "raises an error if measure is called with no block" do
+ lambda{ Hitimes.measure }.should raise_error( Hitimes::Error, /\ANo block given to Interval.measure\Z/ )
+ end
+end
View
3  spec/spec_helper.rb
@@ -1,5 +1,4 @@
require 'rubygems'
require 'rspec'
-
-$: << File.expand_path(File.join(File.dirname(__FILE__),"..","lib"))
+require 'hitimes'
Please sign in to comment.
Something went wrong with that request. Please try again.