13

So I installed jupyter notebook through anaconda and I am working on python 3 kernel.

I am trying to do Time profiling using %time magic command as show here The problem is that it only prints the Wall Time not the CPU Time

using %time or %%time does not help

  • %time prints the wall time for the first line only
  • %%time prints the wall time for the whole cell

I am not sure if there any specif config to print the CPU time

EDIT

To clarify using %%time should print two metrics for the whole cell

  • Metric 1: CPU Times
  • Metric 2: wall time

my problem is that I only get wall time not CPU time.

You may check this link on what is the expected output for %%time

Abdelrahman Shoman
  • 2,882
  • 7
  • 36
  • 61
  • you want `%timeit` for consistent timings this will run the line of code multiple times and return the average, `%%timeit` gives the time for the cell – EdChum Mar 29 '17 at 09:32
  • @EdChum not really .. what I want is the CPU times which should be printed using `%time` .. have a look at the link above to see what I mean – Abdelrahman Shoman Mar 29 '17 at 09:41
  • Ah right, I see your issue, I don't know if you can get the specific cpu time, rather you can get the system and cpu time: https://docs.python.org/3/library/time.html#time.process_time, see related: http://stackoverflow.com/questions/7370801/measure-time-elapsed-in-python. I don't see anything built-in as a magic command in ipython – EdChum Mar 29 '17 at 09:49
  • @EdChum well I see what you are trying to do, however I am sure magic command `%%time` shall show the CPU times. I actually managed to do it as it seem a windows issue. Running on Ubuntu gave the me the desired result – Abdelrahman Shoman Mar 29 '17 at 10:40
  • 1
    That's interesting I didn't think there would be a behavioural difference between ubuntu and windows. Please post an answer as I think this would be useful for others to know – EdChum Mar 29 '17 at 10:41
  • @EdChum actually I faced a lot of issues where there was a behavioral difference between Windows and Ubuntu. One was related to `concurrent.futures` which kept failing on windows but works fine on Ubuntu. Another was related to running the library `mrocklin/fakestockdata` which prints no results on windows but works fine on Ubuntu. – Abdelrahman Shoman Mar 29 '17 at 10:46
  • @EdChum anyhow I added an answer as advised. Thanks for ur help – Abdelrahman Shoman Mar 29 '17 at 10:47

1 Answers1

9

So it seems that my issue was in the environment itself.

Switching from Windows to Ubuntu actually helped me print the CPU times.

Abdelrahman Shoman
  • 2,882
  • 7
  • 36
  • 61
  • maintaining windows OS , is it possible to print CPU usage, hope you resolve the issue, I spent a lot of time on that but, nothing works!! – Ikbel Jun 18 '19 at 09:48
  • 1
    @ikbelbenabdessamad I honestly don't know. I tried everything back then but nothing worked for Windows unfortunately. There seems to be a behavioral difference between Windows and Ubuntu, read the comments above for more details. – Abdelrahman Shoman Jun 20 '19 at 08:54
  • @ikbelbenabdessamad you can now use Linux-based systems on Windows thanks to WSL. Check this article for more details: https://fireship.io/lessons/windows-10-for-web-dev/ – Abdelrahman Shoman Jun 16 '20 at 12:36