summaryrefslogtreecommitdiff
path: root/manyfiles.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-12-01 08:01:56 +0200
committerLars Wirzenius <liw@liw.fi>2021-12-03 19:25:37 +0200
commit6fd336eda6d012136b79ee4f1c37463d43822b96 (patch)
tree18d8d19ef5d57d63df713785a480bf34e0666b9e /manyfiles.py
parente94abe763dd4a1bf4e1b84269c054a4fb56329b0 (diff)
downloadobnam2-6fd336eda6d012136b79ee4f1c37463d43822b96.tar.gz
perf: add benchmark script for the "many empty files" scenario
This isn't great code, but it works, which is enough for now. Sponsored-by: author
Diffstat (limited to 'manyfiles.py')
-rw-r--r--manyfiles.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/manyfiles.py b/manyfiles.py
new file mode 100644
index 0000000..a45d3cd
--- /dev/null
+++ b/manyfiles.py
@@ -0,0 +1,39 @@
+#!/usr/bin/python3
+#
+# Create the desired number of empty files in a directory. A thousand files per
+# subdirectory.
+
+import os
+import sys
+
+
+def subdir(dirname, dirno):
+ pathname = os.path.join(dirname, str(dirno))
+ os.mkdir(pathname)
+ return pathname
+
+
+def create(filename):
+ open(filename, "w").close()
+
+
+DIRFILES = 1000
+
+dirname = sys.argv[1]
+n = int(sys.argv[2])
+
+dirno = 0
+subdirpath = subdir(dirname, dirno)
+fileno = 0
+thisdir = 0
+
+while fileno < n:
+ filename = os.path.join(subdirpath, str(thisdir))
+ create(filename)
+
+ fileno += 1
+ thisdir += 1
+ if thisdir >= DIRFILES:
+ dirno += 1
+ subdirpath = subdir(dirname, dirno)
+ thisdir = 0