summary refs log tree commit diff stats
path: root/code/debug.rb
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-05-09 00:00:00 +0200
committerhut <hut@lavabit.com>2009-05-09 00:00:00 +0200
commita0de7f95bc7525b99b2c2e16f566e0ee367e9c3c (patch)
tree62d1cdf9523f4e8fad28ca7df0e1d696c991d2db /code/debug.rb
parent34bfb32ecf2cea5e5de95980beedb681139d9c01 (diff)
downloadranger-a0de7f95bc7525b99b2c2e16f566e0ee367e9c3c.tar.gz
lots of changes. version 0.2.1 v0.2.1
Diffstat (limited to 'code/debug.rb')
-rw-r--r--code/debug.rb24
1 files changed, 23 insertions, 1 deletions
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