Skip to content
Snippets Groups Projects
Commit f825382f authored by Karl-Hermann Wieners's avatar Karl-Hermann Wieners
Browse files

file/data: review write timing

parent 73df62e7
No related branches found
No related tags found
1 merge request!11File and Data Systems
Pipeline #71273 passed
%% Cell type:markdown id:14cac4fd tags:
# Measure write behavior
%% Cell type:code id:bc0cdf17-1d21-4ade-a090-45101abf8ab5 tags: %% Cell type:code id:bc0cdf17-1d21-4ade-a090-45101abf8ab5 tags:
``` python ``` python
import getpass
import os
import timeit import timeit
user = getpass.getuser()
destination = f"/scratch/{user[0]}/{user}"
``` ```
%% Cell type:code id:bcf39570-a5bc-4af4-9354-06a801222826 tags: %% Cell type:code id:bcf39570-a5bc-4af4-9354-06a801222826 tags:
``` python ``` python
def write (path, length, blocksize=1024**2): def run_write (path, length, blocksize=1024**2):
with open(path, "wb") as of:
data = bytearray(blocksize) (times, remainder) = divmod(length, blocksize)
times = length // (blocksize) data = bytearray(blocksize)
remainder = length % blocksize
for i in range (times): of = open(path, "wb")
of.write(data) for i in range(times):
if remainder: of.write(data)
of.write(bytearray(remainder)) if remainder:
of.close() of.write(bytearray(remainder))
of.close()
``` ```
%% Cell type:code id:34a59ea9-52c9-4c3f-8664-a5a97882e5e0 tags: %% Cell type:code id:34a59ea9-52c9-4c3f-8664-a5a97882e5e0 tags:
``` python ``` python
duration = {} duration = {}
duration['1GB'] = timeit.timeit(lambda : write("/scratch/k/k202134/test.1GB", (1024**3)), number =1) duration['1GB'] = timeit.timeit(lambda : run_write(f"{destination}/test.1GB", (1024**3)), number = 1)
print (duration) print(duration)
```
%% Cell type:code id:6b6b7c16 tags:
``` python
os.remove(f"{destination}/test.1GB")
``` ```
%% Output %% Cell type:markdown id:b1615912 tags:
### Other ideas
{'1GB': 0.5966405299986945} %% Cell type:code id:658a2847 tags:
``` python
destination = f"/dev/shm/{user}"
# destination = f"/tmp/{user}"
os.mkdir(destination)
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment