title: Python 3.3: LAN speed test which calculates the read & write speeds and then returns the figure to Excel
body: <p>I'm creating a LAN speed test which creates a data file in a specified location of a specified size and records the speed at which it is created/read. For the most part this is working correctly, there is just one problem: the read speed is ridiculously fast because all it's doing is timing how long it takes for the file to open, rather than how long it takes for the file to actually be readable (if that makes sense?).</p>
  
  <p>So far I have this:</p>
  
  <pre><code>import time
  import pythoncom
  from win32com.client import Dispatch
  import os
  
  # create file - write speed
  myPath = input('Where do you want to write the file?')
  size_MB = int(input('What sized file do you want to test with? (MB)'))
  size_B = size_MB * 1024 * 1024
  fName = '\pydatafile'
  #start timer
  start = time.clock()
  f = open(myPath + fName,'w')
  f.write("\x00" * size_B)
  f.close()
  
  # how much time it took
  elapsed = (time.clock() -start)
  print ("It took", elapsed, "seconds to write the", size_MB, "MB file")
  time.sleep(1)
  writeMBps = size_MB / elapsed
  print("That's", writeMBps, "MBps.")
  time.sleep(1)
  writeMbps = writeMBps * 8
  print("Or", writeMbps, "Mbps.")
  time.sleep(2)
  
  # open file - read speed
  startRead = time.clock()
  f = open(myPath + fName,'r')
  
  # how much time it took
  elapsedRead = (time.clock() - startRead)
  print("It took", elapsedRead,"seconds to read the", size_MB,"MB file")
  time.sleep(1)
  readMBps = size_MB / elapsedRead
  print("That's", readMBps,"MBps.")
  time.sleep(1)
  readMbps = readMBps * 8
  print("Or", readMbps,"Mbps.")
  time.sleep(2)
  f.close()
  
  # delete the data file
  os.remove(myPath + fName)
  
  # record results on Excel
  xl = Dispatch('Excel.Application')
  xl.visible= 0
  wb = xl.Workbooks.Add(r'C:\File\Location')
  ws = wb.Worksheets(1)
  
  # Write speed result
  #
  # loop until empty cell is found in column
  col = 1
  row = 1
  empty = False
  
  while not empty:
      val = ws.Cells(row,col).value
      print("Looking for next available cell to write to...")
      if val == None:
          print("Writing result to cell")
          ws.Cells(row,col).value = writeMbps
          empty = True
      row += 1
  
  # Read speed result
  #
  # loop until empty cell is found in column
  col = 2
  row = 1
  empty = False
  
  while not empty:
      val = ws.Cells(row,col).value
      print("Looking for next available cell to write to...")
      if val == None:
          print("Writing result to cell")
          ws.Cells(row,col).value = readMbps
          empty = True
      row += 1
  
  
  xl.Run('Save')
  xl.Quit()
  
  pythoncom.CoUninitialize()
  </code></pre>
  
  <p>How can I make this so the read speed is correct?</p>
  
  <p>Thanks a lot</p>