diff --git a/benchmark.py b/benchmark.py index 4e1a975..fc62527 100644 --- a/benchmark.py +++ b/benchmark.py @@ -131,12 +131,17 @@ def get_tree_size(path): return size +def clear_system_cache(): + os.system("sudo bash -c 'echo 3 > /proc/sys/vm/drop_caches'") + + def benchmark(path, get_size=False): sizes = {} if get_size: def do_os_walk(): size = 0 + clear_system_cache() for root, dirs, files in os_walk_func(path): for filename in files: fullname = os.path.join(root, filename) @@ -144,20 +149,23 @@ def benchmark(path, get_size=False): sizes['os_walk'] = size def do_scandir_walk(): + clear_system_cache() sizes['scandir_walk'] = get_tree_size(path) else: def do_os_walk(): + clear_system_cache() for root, dirs, files in os_walk_func(path): pass def do_scandir_walk(): + clear_system_cache() for root, dirs, files in scandir.walk(path): pass # Run this once first to cache things, so we're not benchmarking I/O - print("Priming the system's cache...") - do_scandir_walk() + #print("Priming the system's cache...") + #do_scandir_walk() # Use the best of 3 time for each of them to eliminate high outliers os_walk_time = 1000000 diff --git a/scandir.py b/scandir.py index a3d75be..8453f4d 100644 --- a/scandir.py +++ b/scandir.py @@ -466,6 +466,7 @@ elif sys.platform.startswith(('linux', 'darwin')) or 'bsd' in sys.platform: def __init__(self, scandir_path, name, d_type): self._scandir_path = scandir_path self.name = name + #assert self._d_type != DT_UNKNOWN self._d_type = d_type self._stat = None self._lstat = None