summary refs log tree commit diff stats
path: root/test/dirsize_benchmark.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/dirsize_benchmark.py')
-rw-r--r--test/dirsize_benchmark.py26
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))
evious revision' href='/akspecs/ranger/blame/HACKING?h=v1.1.0&id=62cd83bace8e77cd1ff7028da6cf65d0d1defa27'>^
3ee05c16 ^

f8f6f7f9 ^






29028631 ^
f8f6f7f9 ^









f8f6f7f9 ^










1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80