def test_delayms(delayms):  
  """ Tests millisecond delay function. """

  n_tests = [1000, 1000, 1000, 1000,  100,   40,  10,   4,    2,   1]
  tests   = [   0,  0.1,  0.5,    1,   10,  50, 100, 500, 1000, 5000]

  # Uncomment to test a 1 minute delay:
  #tests.append(60000); n_tests.append(1)

  total_error = 0.0
  time_no_delay = 0 

  for i in range(len(n_tests)):
    total = 0.0
    error = 0.0
    for j in range(n_tests[i]):
      before = time.time()
      t = tests[i]
      if (t != 0): 
        delayms(t)
        # If testing no delay, i.e. t=0, then we don't
        # call the delay function. That way we can record
        # the time it takes to call the time() functions,
        # get test values, etc.
      total += time.time() - before 

    avg = (total/n_tests[i])
    avg *= 1000 # sec -> msec
    # Subtract time recorded without calling delayms():
    avg -= time_no_delay 
    if (t == 0): time_no_delay = avg # Record no delay time
    error = abs(avg-t)
    if (t): 
      total_error += error
      # Because our no delay test doesn't call delayms(),
      # it wouldn't make sense to include it in our average error.
    print "%10.1f msec delay: time = %0.3f msec, error = %0.3f" %\
           (tests[i], avg, error)

  print (total_error/len(n_tests)) % "\n  avg error = +- %0.3f msec\n"

#------------------------------------
dataset/ETHPy150Open graycatlabs/PyBBIO/tests/sleep_test.py/test_delayms/swapped operands of `%`