leonsas
leonsas

Reputation: 4908

python cpu consumption

I wrote a simple python program that looks to me like it should be cpu intensive:

for a in range(0,1500):
      for b in range (0,a):
            for c in range(0,b):
                   x = a+b+c
                   print x

What happens is that it takes a really long time on solving it, but cpu consumption stays at around 25%. Why does this happens insead of using more cpu for a shorter time?

Upvotes: 0

Views: 366

Answers (1)

interjay
interjay

Reputation: 110202

You're probably running this on a quad-core CPU. Since this code will only run on one core, it will show as taking 25% of the total, when the single core is actually at 100%.

On some operating systems, CPU usage will be shown as 100% per core (so that the total can go above 100%). On those operating systems your code should show 100% CPU usage.

Upvotes: 8

Related Questions