diff options
author | hut <hut@lavabit.com> | 2009-11-24 16:50:20 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2009-11-24 16:50:20 +0100 |
commit | f6f26231a1a2c886f43d9ec965eb7903180067fb (patch) | |
tree | 2340d5a6b5dfb97e447b90ab9e1f45a8d4bdffba /test/dirsize_benchmark.py | |
parent | 798d06a2317a5bb4ee38cec4d1d4f5d428d75593 (diff) | |
download | ranger-f6f26231a1a2c886f43d9ec965eb7903180067fb.tar.gz |
corrected test, added some stuff
Diffstat (limited to 'test/dirsize_benchmark.py')
-rw-r--r-- | test/dirsize_benchmark.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/dirsize_benchmark.py b/test/dirsize_benchmark.py new file mode 100644 index 00000000..38f0bfd7 --- /dev/null +++ b/test/dirsize_benchmark.py @@ -0,0 +1,26 @@ +import os, time +class Dirsize(): + def a(path): + return len(os.listdir(path)) + + def b(path): + for _, dirs, files in os.walk(path): + return len(files) + len(dirs) + + def c(path): + first = next(os.walk(path)) + return len(first[1]) + len(first[2]) + +paths = { + '/usr/lib': None, + '/usr/bin': None, + '/home/hut': None +} + +for key in paths.keys(): + paths[key] = Dirsize.a(key) # assume Dirsize.a() returns a correct result + for algo in ['a', 'b', 'c']: + t = time.time() + for i in range(4): + assert Dirsize.__dict__[algo](key) == paths[key] + print("algorithm %s: %20s: %f" % (algo, key, time.time() - t)) |