summary refs log tree commit diff stats
path: root/test
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-04-29 16:14:50 +0200
committerhut <hut@lavabit.com>2010-04-29 19:23:37 +0200
commitd76fd5b7666cd1e7b9ff4eb51a822e1ab41fac28 (patch)
treef6d53c1c9be06fb7320f43bed0ee4539aa74583f /test
parentbb5bfad4426eac02d0d855dd7f6ccf8ed5cc84f9 (diff)
downloadranger-d76fd5b7666cd1e7b9ff4eb51a822e1ab41fac28.tar.gz
Separated benchmark from testcase
Diffstat (limited to 'test')
-rw-r--r--test/__init__.py2
-rw-r--r--test/bm_loader.py119
-rw-r--r--test/tc_loader.py138
3 files changed, 134 insertions, 125 deletions
diff --git a/test/__init__.py b/test/__init__.py
index c2f9bde2..e5f8a300 100644
--- a/test/__init__.py
+++ b/test/__init__.py
@@ -17,7 +17,7 @@ import os, sys
 
 __all__ = [ x[0:x.index('.')] \
 		for x in os.listdir(os.path.dirname(__file__)) \
-		if x.startswith('tc_') ]
+		if x.startswith('tc_') or x.startswith('bm_')]
 
 def init():
 	sys.path.append(os.path.abspath(os.path.join(sys.path[0], '..')))
diff --git a/test/bm_loader.py b/test/bm_loader.py
new file mode 100644
index 00000000..bdef3768
--- /dev/null
+++ b/test/bm_loader.py
@@ -0,0 +1,119 @@
+from ranger.core.loader import Loader
+from ranger.fsobject import Directory, File
+from ranger.ext.openstruct import OpenStruct
+import os
+from ranger.shared import FileManagerAware, SettingsAware
+from test import Fake
+from os.path import realpath, join, dirname
+TESTDIR = realpath(join(dirname(__file__), 'testdir'))
+
+def raw_load_content(self):
+	"""
+	The method which is used in a Directory object to load stuff.
+	Keep this up to date!
+	"""
+
+	from os.path import join, isdir, basename
+	from os import listdir
+	import ranger.ext.mount_path
+
+	self.loading = True
+	self.load_if_outdated()
+
+	try:
+		if self.exists and self.runnable:
+			self.mount_path = ranger.ext.mount_path.mount_path(self.path)
+
+			filenames = []
+			for fname in listdir(self.path):
+				if not self.settings.show_hidden:
+					hfilter = self.settings.hidden_filter
+					if hfilter:
+						if isinstance(hfilter, str) and hfilter in fname:
+							continue
+						if hasattr(hfilter, 'search') and \
+							hfilter.search(fname):
+							continue
+				if isinstance(self.filter, str) and self.filter \
+						and self.filter not in fname:
+					continue
+				filenames.append(join(self.path, fname))
+
+			self.load_content_mtime = os.stat(self.path).st_mtime
+
+			marked_paths = [obj.path for obj in self.marked_items]
+
+			files = []
+			for name in filenames:
+				if isdir(name):
+					try:
+						item = self.fm.env.get_directory(name)
+					except:
+						item = Directory(name)
+				else:
+					item = File(name)
+				item.load_if_outdated()
+				files.append(item)
+
+			self.disk_usage = sum(f.size for f in files if f.is_file)
+
+			self.scroll_offset = 0
+			self.filenames = filenames
+			self.files = files
+
+			self._clear_marked_items()
+			for item in self.files:
+				if item.path in marked_paths:
+					self.mark_item(item, True)
+				else:
+					self.mark_item(item, False)
+
+			self.sort()
+
+			if len(self.files) > 0:
+				if self.pointed_obj is not None:
+					self.sync_index()
+				else:
+					self.move(to=0)
+		else:
+			self.filenames = None
+			self.files = None
+
+		self.cycle_list = None
+		self.content_loaded = True
+		self.determine_infostring()
+		self.correct_pointer()
+
+	finally:
+		self.loading = False
+
+
+class benchmark_load(object):
+	def __init__(self):
+		self.loader = Loader()
+		fm = OpenStruct(loader=self.loader)
+		SettingsAware.settings = Fake()
+		FileManagerAware.fm = fm
+		self.dir = Directory(TESTDIR)
+
+	def bm_run(self, n):
+		for _ in range(n):
+			self.dir.load_content(schedule=True)
+			while self.loader.has_work():
+				self.loader.work()
+
+
+class benchmark_raw_load(object):
+	def __init__(self):
+		SettingsAware.settings = Fake()
+		self.dir = Directory(TESTDIR)
+
+	def bm_run(self, n):
+		generator = self.dir.load_bit_by_bit()
+		for _ in range(n):
+			raw_load_content(self.dir)
+
+def bm_loader(n):
+	"""Do some random calculation"""
+	tloader = benchmark_load(N)
+	traw = benchmark_raw_load(N)
diff --git a/test/tc_loader.py b/test/tc_loader.py
index 22f866ec..53ac5617 100644
--- a/test/tc_loader.py
+++ b/test/tc_loader.py
@@ -18,7 +18,6 @@ if __name__ == '__main__': from __init__ import init; init()
 import unittest
 import os
 from os.path import realpath, join, dirname
-from time import time
 
 from test import Fake
 from ranger.shared import FileManagerAware, SettingsAware
@@ -29,115 +28,6 @@ from ranger.ext.openstruct import OpenStruct
 TESTDIR = realpath(join(dirname(__file__), 'testdir'))
 #TESTDIR = "/usr/sbin"
 
-def raw_load_content(self):
-	"""
-	The method which is used in a Directory object to load stuff.
-	Keep this up to date!
-	"""
-
-	from os.path import join, isdir, basename
-	from os import listdir
-	import ranger.ext.mount_path
-
-	self.loading = True
-	self.load_if_outdated()
-
-	try:
-		if self.exists and self.runnable:
-			self.mount_path = ranger.ext.mount_path.mount_path(self.path)
-
-			filenames = []
-			for fname in listdir(self.path):
-				if not self.settings.show_hidden:
-					hfilter = self.settings.hidden_filter
-					if hfilter:
-						if isinstance(hfilter, str) and hfilter in fname:
-							continue
-						if hasattr(hfilter, 'search') and \
-							hfilter.search(fname):
-							continue
-				if isinstance(self.filter, str) and self.filter \
-						and self.filter not in fname:
-					continue
-				filenames.append(join(self.path, fname))
-
-			self.load_content_mtime = os.stat(self.path).st_mtime
-
-			marked_paths = [obj.path for obj in self.marked_items]
-
-			files = []
-			for name in filenames:
-				if isdir(name):
-					try:
-						item = self.fm.env.get_directory(name)
-					except:
-						item = Directory(name)
-				else:
-					item = File(name)
-				item.load_if_outdated()
-				files.append(item)
-
-			self.disk_usage = sum(f.size for f in files if f.is_file)
-
-			self.scroll_offset = 0
-			self.filenames = filenames
-			self.files = files
-
-			self._clear_marked_items()
-			for item in self.files:
-				if item.path in marked_paths:
-					self.mark_item(item, True)
-				else:
-					self.mark_item(item, False)
-
-			self.sort()
-
-			if len(self.files) > 0:
-				if self.pointed_obj is not None:
-					self.sync_index()
-				else:
-					self.move(to=0)
-		else:
-			self.filenames = None
-			self.files = None
-
-		self.cycle_list = None
-		self.content_loaded = True
-		self.determine_infostring()
-		self.last_update_time = time()
-		self.correct_pointer()
-
-	finally:
-		self.loading = False
-
-
-def benchmark_load(n):
-	loader = Loader()
-	fm = OpenStruct(loader=loader)
-	SettingsAware.settings = Fake()
-	FileManagerAware.fm = fm
-	dir = Directory(TESTDIR)
-
-	t1 = time()
-	for _ in range(n):
-		dir.load_content(schedule=True)
-		while loader.has_work():
-			loader.work()
-	t2 = time()
-	return t2 - t1
-
-
-def benchmark_raw_load(n):
-	SettingsAware.settings = Fake()
-	dir = Directory(TESTDIR)
-	generator = dir.load_bit_by_bit()
-	t1 = time()
-	for _ in range(n):
-		raw_load_content(dir)
-	t2 = time()
-	return t2 - t1
-
-
 class Test1(unittest.TestCase):
 	def test_loader(self):
 		loader = Loader()
@@ -165,20 +55,20 @@ class Test1(unittest.TestCase):
 		#print(iterations)
 		self.assertNotEqual(None, dir.files)
 		self.assertFalse(loader.has_work())
-
-	def test_get_overhead_of_loader(self):
-		N = 5
-		tloader = benchmark_load(N)
-		traw = benchmark_raw_load(N)
-		#traw1k = 250.0
-		#traw = traw1k * N / 1000.0
-		#print("Loader: {0}s".format(tloader))
-		#print("Raw:    {0}s".format(traw))
-		self.assertTrue(tloader > traw)
-		overhead = tloader * 100 / traw - 100
-		self.assertTrue(overhead < 2, "overhead of loader too high: {0}" \
-				.format(overhead))
-		#print("Overhead: {0:.5}%".format(overhead))
+#
+#	def test_get_overhead_of_loader(self):
+#		N = 5
+#		tloader = benchmark_load(N)
+#		traw = benchmark_raw_load(N)
+#		#traw1k = 250.0
+#		#traw = traw1k * N / 1000.0
+#		#print("Loader: {0}s".format(tloader))
+#		#print("Raw:    {0}s".format(traw))
+#		self.assertTrue(tloader > traw)
+#		overhead = tloader * 100 / traw - 100
+#		self.assertTrue(overhead < 2, "overhead of loader too high: {0}" \
+#				.format(overhead))
+#		#print("Overhead: {0:.5}%".format(overhead))
 
 
 if __name__ == '__main__':