Skip to content

Instantly share code, notes, and snippets.

@ganadist
Created December 17, 2018 14:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ganadist/f7f8a4a9f9bbf0ea62630dae28a060db to your computer and use it in GitHub Desktop.
Save ganadist/f7f8a4a9f9bbf0ea62630dae28a060db to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import os
import resource
import time
N_CPU = os.sysconf('SC_NPROCESSORS_ONLN')
class Usage:
def __init__(self):
self.start_time = 0
def __enter__(self, *args):
print(args)
self.res_start = resource.getrusage(resource.RUSAGE_CHILDREN)
self.start_time = time.time()
def __exit__(self, *args):
duration = time.time() - self.start_time
res_end = resource.getrusage(resource.RUSAGE_CHILDREN)
stime = res_end.ru_stime - self.res_start.ru_stime
utime = res_end.ru_utime - self.res_start.ru_utime
idle = duration - (stime + utime) / N_CPU
print(
f'user = {utime} stime = {stime} total = {duration} idle = {idle}')
if __name__ == '__main__':
count = 10
dirs = list(map(lambda x: str(x), range(count)))
os.system(f'rm -rf {" ".join(dirs)}')
with Usage():
for i in dirs:
os.system(
f'git clone https://github.com/ganadist/AndroidPlatformBuilder {i}')
os.system(f'rm -rf {" ".join(dirs)}')
with Usage():
for i in dirs:
os.system(
f'git clone ssh://github.com/ganadist/AndroidPlatformBuilder {i}')
os.system(f'rm -rf {" ".join(dirs)}')
@ganadist
Copy link
Author

git clone https://blahblah x 10 : user = 0.477663 stime = 0.20673899999999998 total = 14.000959157943726 idle = 13.915408907943725
git clone ssh://blahblah x 10 : user = 0.445813 stime = 0.16432599999999997 total = 34.26047897338867 idle = 34.18421159838867

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment