Skip to content

Instantly share code, notes, and snippets.

@hirokai
Created December 15, 2014 19:15
Show Gist options
  • Save hirokai/43a292a82743ba31848a to your computer and use it in GitHub Desktop.
Save hirokai/43a292a82743ba31848a to your computer and use it in GitHub Desktop.
Dispy template (algorithm)
def compute(i):
import time,socket
host = socket.gethostname()
time.sleep(1)
return (host, i)
def search():
import fnmatch
import os
matches = []
for root, dirnames, filenames in os.walk('/Volumes/Macintosh HD/Google Drive/Groves/SEM'):
for filename in fnmatch.filter(filenames, '*.tiff'):
matches.append(os.path.join(root, filename))
return matches
def main(n):
import time
print('testing compute')
initiala = time.time()
files = search()
files = files[0:n]
print '%d files.'%(len(files))
import numpy as np
spent = []
for i in range(len(files)):
initial = time.time()
host,res = compute(i)
final = time.time()
spent.append(final-initial)
finala = time.time()
print('Process time: %.2f sec (%d jobs, %.3f sec/job)'%(finala-initiala, len(spent), np.mean(spent)))
return (finala-initiala, len(spent), np.mean(spent))
if __name__ == '__main__':
res = []
for n in [10,30,100,300]:
res.append(main(n))
print res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment