forked from edsu/bagit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench.py
More file actions
executable file
·46 lines (37 loc) · 1.19 KB
/
bench.py
File metadata and controls
executable file
·46 lines (37 loc) · 1.19 KB
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
#!/usr/bin/env python
"""
This is a little benchmarking script to exercise bagit.make_bag
using 1-8 parallel processes. It will download some images from
NASA for use in bagging the first time it is run.
"""
import os
import ftplib
import timeit
# fetch some images from NASA to bag up
if not os.path.isdir('bench-data'):
print "fetching some images to bag up from nasa"
os.mkdir('bench-data')
ftp = ftplib.FTP('nssdcftp.gsfc.nasa.gov')
ftp.login()
ftp.cwd('/photo_gallery/hi-res/planetary/mars/')
files = []
ftp.retrlines('NLST', files.append)
for file in files:
print "fetching %s" % file
fh = open(os.path.join('bench-data', file), 'wb')
ftp.retrbinary('RETR %s' % file, fh.write)
fh.close()
# bag up bench-data using n processes
statement = """
import os
import bagit
if os.path.isdir('bench-data/data'):
os.system("rm bench-data/bag*")
os.system("mv bench-data/data/* bench-data/")
os.system("rmdir bench-data/data")
bagit.make_bag('bench-data', processes=%s)
"""
# try 1-8 parallel processes
for p in range(1, 9):
t = timeit.Timer(statement % p)
print "%s processes: %.2f seconds " % (p, (10 * t.timeit(number=10) / 10))