0

I have found this post in which, the first answer tells how to get the execution time of a program.

I have tried to implement it in my code as

import time
start_time = time.time()

import nod16

print("--- %s seconds ---" % (time.time() - start_time))

where nodo 16 is a program also generated by me. As you can tell, there are another 15 programs between start_time and print.

Unfortunately, I get the following error once I run my code:

    print("--- %s seconds ---" % (time.time() - start_time))

NameError: name 'time' is not defined

I know this happens because I have to import another program. Unfortunately, the original post doesn't explain how to do this importing code. Can someone help?

slow_learner
  • 337
  • 1
  • 2
  • 15
  • 1
    Strange, code should work. Are you sure time is note redefined somewhere in you modules ? Maybe try to check by saving `time.time` in this script for example `time6543236 = time.time` then call it as `time6543236()` – hpchavaz Nov 15 '21 at 09:47
  • The code should run. That error means `time` is not imported which is not the case in your code if you run those lines on a script – ezzeddin Nov 15 '21 at 10:45
  • importing `nod16` should not effect the time module. But let's say somehow it does. Just use `as` to import the `time` module as something else. Such as: `import time as this_is_pythons_builtin_time_module`. Then use it as: `start = this_is_pythons_builtin_time_module.time()`. – MSH Nov 15 '21 at 11:31
  • I am afraid this doestn't work `import time as tm start_time = tm.time() ("--- %s seconds ---" % (end_time - float(start_time)))` returns ` end_time = tm.time() NameError: name 'tm' is not defined` – slow_learner Nov 15 '21 at 12:46

0 Answers0