Skip to main content
golf away 27 bytes
Source Link
nneonneo
  • 12.6k
  • 8
  • 31
  • 52

Python, 358 281 268 221221 194 bytes

from time import* import os,time A='%-99o'%int('t12q2lxqkap48euoej9429cstbnazg84zyxflqzi8k1''t12q2lxqkap48euoej9429cstbnazl63ubyryteo49u',36) f=open('/dev/urandom') for i in'0123456': t=os.fork() while t<1:T=int(time.time())%50;(time.sleep,(id,fos.readlinesurandom)[i<A[T+49]])[i<A[T]](1) 

Python, 358 281 268 221 bytes

from time import* import os A='%-99o'%int('t12q2lxqkap48euoej9429cstbnazg84zyxflqzi8k1',36) f=open('/dev/urandom') for i in'0123456': t=os.fork() while t<1:T=int(time())%50;(sleep,(id,f.readlines)[i<A[T+49]])[i<A[T]](1) 

Python, 358 281 268 221 194 bytes

import os,time A='%-99o'%int('t12q2lxqkap48euoej9429cstbnazl63ubyryteo49u',36) for i in'0123456': t=os.fork() while t<1:T=int(time.time())%50;(time.sleep,(id,os.urandom)[i<A[T+49]])[i<A[T]](1) 
added 380 characters in body
Source Link
nneonneo
  • 12.6k
  • 8
  • 31
  • 52

Monochrome is so last year. This uses multiprocessingmultiple processes and syscalls to achieve two color CPU graphs!

from time import* import os A='%-99o'%int('t12q2lxqkap48euoej9429cqv3ek6cy28iluqbnfk5t''t12q2lxqkap48euoej9429cstbnazg84zyxflqzi8k1',36) f=open('/dev/urandom') for i in'0123456': t=os.fork() while t<1:T=int(time())%50;(sleep,(id,f.readlines)[i<A[T+49]])[i<A[T]](1) 

This code assumes you have 8 cores. It should be pretty easy to modify for fewer/more. It is portable to Linux/UNIX systems (though it has only been tested on OS X), and should produce the same two-color output for any CPU monitor that can distinguish User from System CPU time.

Essentially, this works by forking off seven processes, each of which will choose to spend 1 second sleeping, spinning in usermode, or spinning the kernel. Spinning in kernel mode is achieved by requesting large globs of data from /dev/urandom, which forces the driver backing /dev/urandom to spend a lot of "system" CPU cycles.

Monochrome is so last year. This uses multiprocessing and syscalls to achieve two color CPU graphs!

from time import* import os A='%-99o'%int('t12q2lxqkap48euoej9429cqv3ek6cy28iluqbnfk5t',36) f=open('/dev/urandom') for i in'0123456': t=os.fork() while t<1:T=int(time())%50;(sleep,(id,f.readlines)[i<A[T+49]])[i<A[T]](1) 

This code assumes you have 8 cores. It should be pretty easy to modify for fewer/more. It is portable to Linux/UNIX systems, and should produce the same two-color output for any CPU monitor that can distinguish User from System CPU time.

Monochrome is so last year. This uses multiple processes and syscalls to achieve two color CPU graphs!

from time import* import os A='%-99o'%int('t12q2lxqkap48euoej9429cstbnazg84zyxflqzi8k1',36) f=open('/dev/urandom') for i in'0123456': t=os.fork() while t<1:T=int(time())%50;(sleep,(id,f.readlines)[i<A[T+49]])[i<A[T]](1) 

This code assumes you have 8 cores. It should be pretty easy to modify for fewer/more. It is portable to Linux/UNIX systems (though it has only been tested on OS X), and should produce the same two-color output for any CPU monitor that can distinguish User from System CPU time.

Essentially, this works by forking off seven processes, each of which will choose to spend 1 second sleeping, spinning in usermode, or spinning the kernel. Spinning in kernel mode is achieved by requesting large globs of data from /dev/urandom, which forces the driver backing /dev/urandom to spend a lot of "system" CPU cycles.

shorten considerably, add CPU History output
Source Link
nneonneo
  • 12.6k
  • 8
  • 31
  • 52

Python, 358 281 268268 221 bytes

from time import* from multiprocessingimport import*os A='%-99o'%int('t12q2lxqkap48euoej9429cstbnazg84zyxflqzi8k1''t12q2lxqkap48euoej9429cqv3ek6cy28iluqbnfk5t',36) f=open('/dev/urandom') deffor Fi in'0123456': t=os.fork(n): while 1t<1:T=int(time())%50;(sleep,(id,f.readlines)[n<A[T+49]][i<A[T+49]])[n<A[T]][i<A[T]](1) for i in'012345':Process(None,F,i,i).start() F('6') 

Activity Monitor outputActivity Monitor CPU Load graph Activity Monitor CPU History graph

Repeats on the CPU History graph

BothAll outputs were generated with an update speed of 1s. No significant background tasks were running, though this output quite easily beats out any single-threaded CPU task.

This code assumes you have 8 cores. It should be pretty easy to modify for fewer/more. It is portable to Linux/UNIX systems, and should produce the same two-color output for any CPU monitor that can distinguish User from System CPU time.

EDITED [07/21]: Shortened significantly by using fork() instead of multiprocessing.Process (/dev/urandom only works on *NIX systems anyway so this doesn't reduce portability). Note however that the program now spawns background tasks; you may have to killall Python (or similar) to get rid of the CPU-eaters.

Python, 358 281 268 bytes

from time import* from multiprocessing import* A='%-99o'%int('t12q2lxqkap48euoej9429cstbnazg84zyxflqzi8k1',36) f=open('/dev/urandom') def F(n): while 1:T=int(time())%50;(sleep,(id,f.readlines)[n<A[T+49]])[n<A[T]](1) for i in'012345':Process(None,F,i,i).start() F('6') 

Activity Monitor output

Both outputs were generated with an update speed of 1s. No significant background tasks were running, though this output quite easily beats out any single-threaded CPU task.

This code assumes you have 8 cores. It should be pretty easy to modify for fewer/more. It is portable to Linux/UNIX systems, and should produce the same two-color output for any CPU monitor that can distinguish User from System CPU time.

Python, 358 281 268 221 bytes

from time import* import os A='%-99o'%int('t12q2lxqkap48euoej9429cqv3ek6cy28iluqbnfk5t',36) f=open('/dev/urandom') for i in'0123456': t=os.fork() while t<1:T=int(time())%50;(sleep,(id,f.readlines)[i<A[T+49]])[i<A[T]](1) 

Activity Monitor CPU Load graph Activity Monitor CPU History graph

Repeats on the CPU History graph

All outputs were generated with an update speed of 1s. No significant background tasks were running, though this output quite easily beats out any single-threaded CPU task.

This code assumes you have 8 cores. It should be pretty easy to modify for fewer/more. It is portable to Linux/UNIX systems, and should produce the same two-color output for any CPU monitor that can distinguish User from System CPU time.

EDITED [07/21]: Shortened significantly by using fork() instead of multiprocessing.Process (/dev/urandom only works on *NIX systems anyway so this doesn't reduce portability). Note however that the program now spawns background tasks; you may have to killall Python (or similar) to get rid of the CPU-eaters.

shorten by 13 chars
Source Link
nneonneo
  • 12.6k
  • 8
  • 31
  • 52
Loading
golf the code
Source Link
nneonneo
  • 12.6k
  • 8
  • 31
  • 52
Loading
more letters
Source Link
nneonneo
  • 12.6k
  • 8
  • 31
  • 52
Loading
added 184 characters in body
Source Link
nneonneo
  • 12.6k
  • 8
  • 31
  • 52
Loading
Source Link
nneonneo
  • 12.6k
  • 8
  • 31
  • 52
Loading