Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. import time
  2. import sys
  3. from multiprocessing import Process
  4.  
  5.  
  6. numOfLoops = 10000000
  7.  
  8. if (len(sys.argv) != 2):
  9. print "Correct Usage: python cpu.py 'no_of_processes'"
  10. sys.exit()
  11.  
  12. #function for each process
  13. def fpOps():
  14. a = float(0.0)
  15. for i in xrange(0, numOfLoops):
  16. a += 0.5
  17. #print a #for debugging purpose
  18.  
  19. processes = []
  20. numOfProcesses = int(sys.argv[1])
  21. numOfOps = numOfLoops * numOfProcesses
  22.  
  23. for i in xrange(0, numOfProcesses):
  24. processes.append(Process(target=fpOps))
  25.  
  26. start = time.time()
  27. for process in processes:
  28. process.start()
  29. for process in processes:
  30. process.join()
  31. end = time.time()
  32.  
  33. execTime = end - start
  34. print "Exec Time " , execTime
  35.  
  36.  
  37. FLOPS = (float(numOfOps/execTime))
  38. print "FLOPS : " , FLOPS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement