Skip to content

Instantly share code, notes, and snippets.

@albertofwb
Last active June 18, 2019 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save albertofwb/412b0863f2f548a8c7e6c693ed1fc6f6 to your computer and use it in GitHub Desktop.
Save albertofwb/412b0863f2f548a8c7e6c693ed1fc6f6 to your computer and use it in GitHub Desktop.
create files benchmark between windows and posix system
from os import path
from os import mkdir
from os import getenv
from os import name as os_name
from time import time
total_files_count = 12345
MAX_FILES_SINGLE_DIR = 500
DEBUG_DIR_NAME = "TestCreateFiles"
DIR_PREFIX = "dir_"
FILE_PREFIX = "file_"
dirs_count = int(total_files_count / MAX_FILES_SINGLE_DIR)
assert dirs_count > 0
sys_tmp_dir = getenv("TMP")
if sys_tmp_dir is None and os_name == 'posix':
sys_tmp_dir = "/tmp"
assert sys_tmp_dir is not None
test_dir_root = path.join(sys_tmp_dir, DEBUG_DIR_NAME)
tmp = test_dir_root
c = 1
while path.exists(tmp):
c += 1
tmp = test_dir_root + str(c)
test_dir_root = tmp
assert not path.exists(test_dir_root)
mkdir(test_dir_root)
print("test dir is ", test_dir_root)
print("dirs_count", dirs_count)
start_time = time()
for i in range(dirs_count):
dir_name = path.join(test_dir_root, DIR_PREFIX + str(i))
if not path.exists(dir_name):
# print("making dir", dir_name)
mkdir(dir_name)
for j in range(MAX_FILES_SINGLE_DIR):
file_path = path.join(dir_name, "{name}{index}.txt".format(name=FILE_PREFIX, index=j))
# print("create file", file_path)
# create blank files only
open(file_path, 'w').close()
#with open(file_path, 'w') as fp:
# fp.write(file_path)
end_time = time()
print("create %d files cost %d seconds" % (total_files_count, int(end_time - start_time)))
# win10 1809 cost 20s
# win7 64 cost 19s
# Deepin 15.10 cost 4s
# Ubuntu 18.04.02 LTS server cost 2.8s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment