From d76fd5b7666cd1e7b9ff4eb51a822e1ab41fac28 Mon Sep 17 00:00:00 2001 From: hut Date: Thu, 29 Apr 2010 16:14:50 +0200 Subject: Separated benchmark from testcase --- test/bm_loader.py | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 test/bm_loader.py (limited to 'test/bm_loader.py') 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) -- cgit 1.4.1-2-gfad0 From 5fab6bc0c6f26d01571dc38f1a6da07c9b7d93dc Mon Sep 17 00:00:00 2001 From: hut Date: Thu, 29 Apr 2010 19:23:16 +0200 Subject: changed testdir to /usr/include --- test/bm_loader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/bm_loader.py') diff --git a/test/bm_loader.py b/test/bm_loader.py index bdef3768..9ee61801 100644 --- a/test/bm_loader.py +++ b/test/bm_loader.py @@ -5,7 +5,7 @@ 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')) +TESTDIR = realpath(join(dirname(__file__), '/usr/include')) def raw_load_content(self): """ -- cgit 1.4.1-2-gfad0 From bff429683a42eb1124ec8137fe52ae9d5a63ad06 Mon Sep 17 00:00:00 2001 From: hut Date: Mon, 3 May 2010 23:56:15 +0200 Subject: bm_loader: stuff --- test/bm_loader.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'test/bm_loader.py') diff --git a/test/bm_loader.py b/test/bm_loader.py index 9ee61801..33011108 100644 --- a/test/bm_loader.py +++ b/test/bm_loader.py @@ -1,12 +1,16 @@ from ranger.core.loader import Loader from ranger.fsobject import Directory, File from ranger.ext.openstruct import OpenStruct -import os +import os.path from ranger.shared import FileManagerAware, SettingsAware from test import Fake from os.path import realpath, join, dirname +from subprocess import Popen, PIPE TESTDIR = realpath(join(dirname(__file__), '/usr/include')) +def skip(x): + return + def raw_load_content(self): """ The method which is used in a Directory object to load stuff. @@ -22,8 +26,10 @@ def raw_load_content(self): try: if self.exists and self.runnable: + # 0.003s: self.mount_path = ranger.ext.mount_path.mount_path(self.path) + # 0.1s: filenames = [] for fname in listdir(self.path): if not self.settings.show_hidden: @@ -38,11 +44,13 @@ def raw_load_content(self): 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] + # 2.85s: files = [] for name in filenames: if isdir(name): @@ -55,6 +63,7 @@ def raw_load_content(self): item.load_if_outdated() files.append(item) + # 0.2s self.disk_usage = sum(f.size for f in files if f.is_file) self.scroll_offset = 0 @@ -88,6 +97,7 @@ def raw_load_content(self): self.loading = False +@skip class benchmark_load(object): def __init__(self): self.loader = Loader() @@ -117,3 +127,27 @@ def bm_loader(n): """Do some random calculation""" tloader = benchmark_load(N) traw = benchmark_raw_load(N) + +class benchmark_load_varieties(object): + def bm_ls(self, n): + for _ in range(n): + Popen(["ls", '-l', TESTDIR], stdout=open(os.devnull, 'w')).wait() + + def bm_os_listdir_stat(self, n): + for _ in range(n): + for f in os.listdir(TESTDIR): + path = os.path.join(TESTDIR, f) + os.stat(path) + + def bm_os_listdir(self, n): + for _ in range(n): + for f in os.listdir(TESTDIR): + path = os.path.join(TESTDIR, f) + + def bm_os_listdir_stat_listdir(self, n): + for _ in range(n): + for f in os.listdir(TESTDIR): + path = os.path.join(TESTDIR, f) + os.stat(path) + if os.path.isdir(path): + os.listdir(path) -- cgit 1.4.1-2-gfad0 From da440d3a10b7ab05e9b55968344fff2cbc45da09 Mon Sep 17 00:00:00 2001 From: hut Date: Tue, 4 May 2010 00:06:25 +0200 Subject: Added license header to a few files --- Makefile | 15 +++++++++++++++ all_benchmarks.py | 15 +++++++++++++++ all_tests.py | 15 +++++++++++++++ test/bm_loader.py | 15 +++++++++++++++ 4 files changed, 60 insertions(+) (limited to 'test/bm_loader.py') diff --git a/Makefile b/Makefile index ffa81797..3b429367 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,18 @@ +# Copyright (C) 2009, 2010 Roman Zimbelmann +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + NAME = ranger VERSION = 1.0.4 PYTHON ?= python diff --git a/all_benchmarks.py b/all_benchmarks.py index c03d0d92..abcd051e 100755 --- a/all_benchmarks.py +++ b/all_benchmarks.py @@ -1,4 +1,19 @@ #!/usr/bin/python +# Copyright (C) 2009, 2010 Roman Zimbelmann +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + """Run all the tests inside the test/ directory as a test suite.""" if __name__ == '__main__': from test import * diff --git a/all_tests.py b/all_tests.py index 6693b870..90926918 100755 --- a/all_tests.py +++ b/all_tests.py @@ -1,4 +1,19 @@ #!/usr/bin/python +# Copyright (C) 2009, 2010 Roman Zimbelmann +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + """Run all the tests inside the test/ directory as a test suite.""" if __name__ == '__main__': import unittest diff --git a/test/bm_loader.py b/test/bm_loader.py index 33011108..0604d5ad 100644 --- a/test/bm_loader.py +++ b/test/bm_loader.py @@ -1,3 +1,18 @@ +# Copyright (C) 2009, 2010 Roman Zimbelmann +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + from ranger.core.loader import Loader from ranger.fsobject import Directory, File from ranger.ext.openstruct import OpenStruct -- cgit 1.4.1-2-gfad0 From 83f08a2c6fb92269031af2991eed3c26ec816d3d Mon Sep 17 00:00:00 2001 From: hut Date: Thu, 6 May 2010 02:00:19 +0200 Subject: fsobject: don't unnecessarily use abspath() in __init__ --- ranger/fsobject/directory.py | 9 +++++---- ranger/fsobject/fsobject.py | 9 +++++---- test/bm_loader.py | 3 ++- 3 files changed, 12 insertions(+), 9 deletions(-) (limited to 'test/bm_loader.py') diff --git a/ranger/fsobject/directory.py b/ranger/fsobject/directory.py index 9d12af28..5acf6ca7 100644 --- a/ranger/fsobject/directory.py +++ b/ranger/fsobject/directory.py @@ -81,11 +81,11 @@ class Directory(FileSystemObject, Accumulator, SettingsAware): 'type': lambda path: path.mimetype, } - def __init__(self, path, preload=None): + def __init__(self, path, **kw): assert not os.path.isfile(path), "No directory given!" Accumulator.__init__(self) - FileSystemObject.__init__(self, path, preload=preload) + FileSystemObject.__init__(self, path, **kw) self.marked_items = list() @@ -196,9 +196,10 @@ class Directory(FileSystemObject, Accumulator, SettingsAware): try: item = self.fm.env.get_directory(name) except: - item = Directory(name, preload=stats) + item = Directory(name, preload=stats, + path_is_abs=True) else: - item = File(name, preload=stats) + item = File(name, preload=stats, path_is_abs=True) item.load_if_outdated() files.append(item) yield diff --git a/ranger/fsobject/fsobject.py b/ranger/fsobject/fsobject.py index ef52eb88..28e32055 100644 --- a/ranger/fsobject/fsobject.py +++ b/ranger/fsobject/fsobject.py @@ -71,10 +71,11 @@ class FileSystemObject(MimeTypeAware, FileManagerAware): container = False mimetype_tuple = () - def __init__(self, path, preload=None): + def __init__(self, path, preload=None, path_is_abs=False): MimeTypeAware.__init__(self) - path = abspath(path) + if not path_is_abs: + path = abspath(path) self.path = path self.basename = basename(path) self.basename_lower = self.basename.lower() @@ -183,12 +184,12 @@ class FileSystemObject(MimeTypeAware, FileManagerAware): self.infostring = 'sock' elif self.is_directory: try: - self.size = len(os.listdir(self.path)) + self.size = len(os.listdir(self.path)) # bite me except OSError: self.infostring = BAD_INFO self.accessible = False else: - self.infostring = " %d" % self.size + self.infostring = ' %d' % self.size self.accessible = True self.runnable = True elif self.is_file: diff --git a/test/bm_loader.py b/test/bm_loader.py index 0604d5ad..154fea3d 100644 --- a/test/bm_loader.py +++ b/test/bm_loader.py @@ -112,7 +112,6 @@ def raw_load_content(self): self.loading = False -@skip class benchmark_load(object): def __init__(self): self.loader = Loader() @@ -128,6 +127,7 @@ class benchmark_load(object): self.loader.work() +@skip class benchmark_raw_load(object): def __init__(self): SettingsAware.settings = Fake() @@ -143,6 +143,7 @@ def bm_loader(n): tloader = benchmark_load(N) traw = benchmark_raw_load(N) +@skip class benchmark_load_varieties(object): def bm_ls(self, n): for _ in range(n): -- cgit 1.4.1-2-gfad0 From a0e543f8b2adb7afb2822122d786f25b41f08ba2 Mon Sep 17 00:00:00 2001 From: hut Date: Mon, 10 May 2010 10:34:48 +0200 Subject: all_benchmarks: improved --- all_benchmarks.py | 28 ++++++++++++++++++++-------- test/bm_loader.py | 2 -- 2 files changed, 20 insertions(+), 10 deletions(-) (limited to 'test/bm_loader.py') diff --git a/all_benchmarks.py b/all_benchmarks.py index abcd051e..73316658 100755 --- a/all_benchmarks.py +++ b/all_benchmarks.py @@ -16,6 +16,7 @@ """Run all the tests inside the test/ directory as a test suite.""" if __name__ == '__main__': + from re import compile from test import * from time import time from types import FunctionType as function @@ -25,6 +26,16 @@ if __name__ == '__main__': n = int(argv[1]) except IndexError: n = 10 + if len(argv) > 2: + args = [compile(re) for re in argv[2:]] + def allow(name): + for re in args: + if re.search(name): + return True + else: + return False + else: + allow = lambda name: True for key, val in vars().copy().items(): if key.startswith('bm_'): bms.extend(v for k,v in vars(val).items() if type(v) == type) @@ -36,11 +47,12 @@ if __name__ == '__main__': t1 = time() method = getattr(bmobj, attrname) methodname = "{0}.{1}".format(bmobj.__class__.__name__, method.__name__) - try: - method(n) - except: - print("{0} failed!".format(methodname)) - raise - else: - t2 = time() - print("{0:60}: {1:10}s".format(methodname, t2 - t1)) + if allow(methodname): + try: + method(n) + except: + print("{0} failed!".format(methodname)) + raise + else: + t2 = time() + print("{0:60}: {1:10}s".format(methodname, t2 - t1)) diff --git a/test/bm_loader.py b/test/bm_loader.py index 154fea3d..4bfc2db9 100644 --- a/test/bm_loader.py +++ b/test/bm_loader.py @@ -127,7 +127,6 @@ class benchmark_load(object): self.loader.work() -@skip class benchmark_raw_load(object): def __init__(self): SettingsAware.settings = Fake() @@ -143,7 +142,6 @@ def bm_loader(n): tloader = benchmark_load(N) traw = benchmark_raw_load(N) -@skip class benchmark_load_varieties(object): def bm_ls(self, n): for _ in range(n): -- cgit 1.4.1-2-gfad0