From a0de7f95bc7525b99b2c2e16f566e0ee367e9c3c Mon Sep 17 00:00:00 2001 From: hut Date: Sat, 9 May 2009 00:00:00 +0200 Subject: lots of changes. version 0.2.1 --- code/debug.rb | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'code/debug.rb') diff --git a/code/debug.rb b/code/debug.rb index 6261ed0e..d3a97190 100644 --- a/code/debug.rb +++ b/code/debug.rb @@ -1,4 +1,3 @@ - require 'pp' module Debug @@ -25,6 +24,28 @@ module Debug end if LOG_LEVEL > 0 + def bm(descr="benchmark", &block) + # Benchmark + t1 = Time.now + yield + dur = Time.now-t1 + + # substract the durtation of a "bm(..) do end" + dur -= bm_dummy(descr) do end + + # Format the duration + dur *= 1000 + dur = dur > 0 ? dur : 0 + dur = '%0.3f' % dur + logerr("#{descr}: #{dur}ms") + end + + def bm_dummy(descr="benchmark", &block) + t1 = Time.now + yield + return (Time.now-t1) + end + def __log__(obj, level) if level <= LOG_LEVEL obj = obj.nil? ? "checkpoint at #{Time.now}" : obj @@ -63,5 +84,6 @@ module Debug def log(a=nil) end def logpp(a=nil) end def trace() end + def bm(*args, &block) yield end end end -- cgit 1.4.1-2-gfad0