Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Release 0.4.2 (JRuby support and improved performance)

  • Loading branch information...
commit 7545c51c805800033d2bd583b48d067af52fab24 1 parent a67a274
@delano authored
View
6 CHANGES.txt
@@ -1,6 +1,12 @@
BENELUX, CHANGES
+#### 0.4.2 (2009-10-06) ###############################
+
+* ADDED: JRuby support
+* CHANGE: Improved performance
+
+
#### 0.4.1 (2009-10-06) ###############################
* FIXED: Nil @thread error in reporter
View
2  benelux.gemspec
@@ -1,7 +1,7 @@
@spec = Gem::Specification.new do |s|
s.name = "benelux"
s.rubyforge_project = 'benelux'
- s.version = "0.4.1"
+ s.version = "0.4.2"
s.summary = "Benelux: Little freakin' timers for your Ruby codes"
s.description = s.summary
s.author = "Delano Mandelbaum"
View
60 lib/benelux.rb
@@ -5,7 +5,7 @@
require 'selectable'
module Benelux
- VERSION = "0.4.1"
+ VERSION = "0.4.2"
NOTSUPPORTED = [Class, Object, Kernel]
class BeneluxError < RuntimeError; end
@@ -32,7 +32,7 @@ class << self
attr_reader :reporter
end
- @packed_methods = SelectableArray.new
+ @packed_methods = {}
@tracks = SelectableHash.new
@timeline = Timeline.new
@reporter = Reporter.new
@@ -93,22 +93,13 @@ def Benelux.remove_thread_tag(*args) remove_thread_tags *args end
def Benelux.inspect
str = ["Benelux"]
str << "tracks:" << Benelux.tracks.inspect
- str << "timers:" << Benelux.timed_methods.inspect
- #str << "timeline:" << Benelux.timeline.inspect
str.join $/
end
def Benelux.supported?(klass)
!NOTSUPPORTED.member?(klass)
end
-
- def Benelux.timed_methods
- Benelux.packed_methods.filter :kind => :'Benelux::MethodTimer'
- end
- def Benelux.counted_methods
- Benelux.packed_methods.filter :kind => :'Benelux::MethodCounter'
- end
def Benelux.known_thread?(t=Thread.current)
@reporter.thwait.threads.member? t
@@ -123,35 +114,17 @@ def Benelux.reporting_wait
end
def Benelux.packed_method(klass, meth)
- Benelux.packed_methods.filter(klass.to_s.to_sym, meth).first
- end
-
- def Benelux.counted_method(klass, meth)
- Benelux.counted_methods.filter(klass.to_s.to_sym, meth).first
+ return nil unless defined?(Benelux.packed_methods[klass][meth])
+ Benelux.packed_methods[klass][meth]
end
- def Benelux.timed_method(klass, meth)
- Benelux.timed_methods.filter(klass.to_s.to_sym, meth).first
+ def Benelux.packed_method? klass, meth
+ !Benelux.packed_method(klass, meth).nil?
end
- def Benelux.timed_method? klass, meth
- Benelux.packed_method? klass, meth, :'Benelux::MethodTimer'
- end
-
- def Benelux.counted_method? klass, meth
- Benelux.packed_method? klass, meth, :'Benelux::MethodCounter'
- end
-
- def Benelux.packed_method? klass, meth, kind=nil
- list = Benelux.packed_methods.filter(klass.to_s.to_sym, meth)
- list.filter! :kind => kind unless kind.nil?
- !list.empty?
- end
-
-
def Benelux.add_timer klass, meth, &blk
raise NotSupported, klass unless Benelux.supported? klass
- raise AlreadyTimed, klass if Benelux.timed_method? klass, meth
+ raise AlreadyTimed, klass if Benelux.packed_method? klass, meth
Benelux::MethodTimer.new klass, meth, &blk
end
@@ -163,25 +136,6 @@ def Benelux.add_counter klass, meth, &blk
def Benelux.ld(*msg)
@@logger.puts "D: " << msg.join("#{$/}D: ") if debug?
end
-
-
- # Returns an Array of method names for the current class that
- # are timed by Benelux.
- #
- # This is an instance method for objects which have Benelux
- # modified methods.
- def timed_methods
- Benelux.timed_methods.filter(:class => self.class.to_s.to_sym)
- end
-
- # Returns an Array of method names for the current class that
- # are counted by Benelux.
- #
- # This is an instance method for objects which have Benelux
- # modified methods.
- def counted_methods
- Benelux.counted_methods.filter(:class => self.class.to_s.to_sym)
- end
def Benelux.enable_debug; @@debug = true; end
View
15 lib/benelux/packer.rb
@@ -45,7 +45,12 @@ def initialize(k,m,&blk)
self.add_tags :class => @klass.to_s.to_sym,
:meth => @meth.to_sym,
:kind => self.class.to_s.to_sym
- Benelux.packed_methods << self
+
+ Benelux.packed_methods[@klass] ||= {}
+ Benelux.packed_methods[@klass][@meth] = self
+ Benelux.packed_methods[:all] ||= []
+ Benelux.packed_methods[:all] << self
+
end
def install_method
raise "You need to implement this method"
@@ -76,7 +81,7 @@ class MethodTimer < MethodPacker
# generate_method. It calls <tt>@klass.module_eval</tt>
# with the modified line number (helpful for exceptions)
def install_method
- @klass.module_eval generate_packed_method, __FILE__, 89
+ @klass.module_eval generate_packed_method, __FILE__, 94
end
# Creates a method definition (for an eval). The
@@ -109,17 +114,15 @@ def #{@meth}(*args, &block)
class MethodCounter < MethodPacker
attr_reader :counter
def install_method
- @klass.module_eval generate_packed_method, __FILE__, 121
+ @klass.module_eval generate_packed_method, __FILE__, 122
end
def generate_packed_method(callblock=false)
%Q{
- @@__benelux_#{@meth}_counter =
- Benelux.counted_method #{@klass}, :#{@meth}
def #{@meth}(*args, &block)
Benelux.current_track :global unless Benelux.known_thread?
# Get a reference to this MethodCounter instance
- cmd = Benelux.counted_method #{@klass}, :#{@meth}
+ cmd = Benelux.packed_method #{@klass}, :#{@meth}
ret = #{@aliaz}(*args, &block)
count = cmd.determine_count(args, ret)
Benelux.ld "COUNT(:#{@meth}): \#{count}"
View
17 lib/selectable.rb
@@ -20,11 +20,15 @@ class TagsNotInitialized < SelectableError; end
def Selectable.normalize(*tags)
tags.flatten!
tags = tags.first if tags.first.kind_of?(Hash) || tags.first.kind_of?(Array)
- if tags.is_a?(Hash)
- tags = Hash[tags.collect { |n,v| [n, v.to_s] }]
- else
- tags.collect! { |v| v.to_s }
- end
+ # NOTE: The string enforcement is disabled
+ # FOR NOW.
+ #if tags.is_a?(Hash)
+ # #tmp = {}
+ # #tags.each_pair { |n,v| tmp[n] = v.to_s }
+ # #tags = tmp
+ #else
+ # tags.collect! { |v| v.to_s }
+ #end
tags
end
@@ -38,6 +42,9 @@ def Selectable.normalize(*tags)
#
# undefined method `>=' for nil:NilClass
#
+ # It also means you need be aware of the types
+ # of objects you are storing as values. If you
+ # store a Symbol, you must send a Symbol here.
def filter(*tags)
tags = Selectable.normalize tags
# select returns an Array. We want a Selectable.
View
2  lib/selectable/object.rb
@@ -13,7 +13,7 @@ module Object
attr_accessor :tags
def add_tags(tags)
init_tags!
- @tags.merge! Selectable.normalize tags
+ @tags.merge! tags
end
alias_method :add_tag, :add_tags
def add_tags_quick(tags)
View
6 lib/selectable/tags.rb
@@ -31,7 +31,11 @@ def inspect
def ==(other)
if other.is_a?(Array)
- self.values.sort == other.sort
+ # NOTE: This resolves the issue of sorting an Array
+ # with a mix of Object types (Integers, Strings, Symbols).
+ # As in: self.values.sort == other.sort)
+ (self.values.size == other.size) &&
+ (self.values - other).empty?
else
super(other)
end
View
4 tryouts/11_selectable_tryouts.rb
@@ -22,10 +22,6 @@ class ::TaggedItems
base.filter(:even => true)
end
- drill "[] and filter are the same", true do
- base.filter(:even => false) == base.filter(:even => false)
- end
-
dream :class, SelectableArray
dream :object_id, base.object_id
dream :size, 5
Please sign in to comment.
Something went wrong with that request. Please try again.