30
\$\begingroup\$

Introduction

There are lots of utilities out there capable of creating a high CPU load to stress-test your processor(s). On Microsoft Windows, you can even use the on-board calculator.exe, enter a large number like 999999999, and press n! several times to make your CPU(s) work overtime.

But what’s in a solution if you didn’t create it yourself?

The mission

Your mission – if you choose to accept it – is to create the smallest CPU stress-test tool on the planet.

Must…

  1. must produce 100% CPU load until aborted
  2. must take a numeric input, representing the number seconds the stress-test should run
  3. must allow user interaction (keypress, closing terminal window, or something like that) which should enable a user to abort the stress-test and/or quit the program
  4. must target Microsoft Windows, Mac OSx, and/or Linux.
    (Even a hamster could stress a Comodore64… therefore, you must target a current operating system.)

Must not…

  1. must not use 3rd-party programs or tools which replace expected functionality.
    (Proposing shortcuts in the likes of system('cpuStressThing.exe') disqualifies your proposal.)

May…

  1. may use any approach/algorithm/functionality to produce expected 100% CPU load
  2. may use any programming or scripting language
    (as long as it allows practical verification of its functionality by running it)

Winning Condition

Present the smallest sourcecode possible. The winner is the one presenting the most minimal (in size) sourcecode that complies to the above “must” and “must not” conditions. Now, make that baby burn…


EDIT

Since the question came up in the comment area… you only need to target 1 CPU core. I'm definitely not expecting you to produce a multi-core solution. After all, this should be fun – not work.

\$\endgroup\$
8
  • 5
    \$\begingroup\$ Is "100% of one core" enough, or do you mean "100% of a multi-core CPU"? \$\endgroup\$
    – Tobia
    Commented Feb 17, 2014 at 20:43
  • \$\begingroup\$ @Tobia Yep, 1 core is enough. I've edited my question to specifically include that information. Thanks for pointing me to the fact that that wasn't all too clear. \$\endgroup\$
    – e-sushi
    Commented Feb 17, 2014 at 21:12
  • 3
    \$\begingroup\$ do cryptocurrency miners count/ \$\endgroup\$
    – TheDoctor
    Commented Feb 17, 2014 at 21:59
  • 2
    \$\begingroup\$ @TheDoctor If you can make it fit the conditions I described… be my guest. It would surely be interesting to see a cryptocurrency miner that is able to beat (for example) a 36 byte bash script in filesize. \$\endgroup\$
    – e-sushi
    Commented Feb 17, 2014 at 22:07
  • \$\begingroup\$ The problem is that most miners are several thousand lines of code. \$\endgroup\$
    – TheDoctor
    Commented Feb 17, 2014 at 22:18

29 Answers 29

28
\$\begingroup\$

Bash and standard utilities, 36 31 22 29 28 26 bytes

yes :|sh&sleep $1;kill $!
\$\endgroup\$
13
  • 2
    \$\begingroup\$ That looks pretty gorgeous for a Bash code! That's really a nice answer! \$\endgroup\$ Commented Feb 17, 2014 at 21:36
  • \$\begingroup\$ You don't need the : in do :; done. I've found do;done does the job - that'll pull you in 2 bytes. Also +1 for being nearly half the length of my bash solution (I made it overly complicated for no good reason as I forgot about $!). \$\endgroup\$
    – Callie J
    Commented Feb 17, 2014 at 21:45
  • 1
    \$\begingroup\$ @ChrisJ - that doesn't work for me: bash: syntax error near unexpected token `;'. I've tried these bash versions: 3.00.15(1)-release (x86_64-redhat-linux-gnu), 3.2.48(1)-release (x86_64-apple-darwin12), 4.2.25(1)-release (x86_64-pc-linux-gnu) \$\endgroup\$ Commented Feb 17, 2014 at 21:50
  • 1
    \$\begingroup\$ @ChrisJ - I guess you have yourself a 34-byte ksh answer then ;-) \$\endgroup\$ Commented Feb 17, 2014 at 22:05
  • 2
    \$\begingroup\$ I'd put $1 in place of 10 there, just to make it into a script that "takes numeric input". \$\endgroup\$
    – Tobia
    Commented Feb 17, 2014 at 22:45
20
\$\begingroup\$

Bash/iputils (Linux), 14 bytes

ping6 -fw$1 ::

Flood-pings the IPv6 null address, until the -w deadline timer expires

caveat - only consumes 55-60% CPU on my test VM

Edit: - I retract my caveat. While top reports the ping6 process only consumes 55-60% CPU, I see the total CPU idle percentage (2 core VM) approach zero. This presumably is because a good deal of the processing is going on in the kernel as it handles the packets.

Note - must be run as root. As @Tobia comments, this seems like a reasonable requirement for something that will hog the CPU. And the OP approved it in the comments.

\$\endgroup\$
5
  • 6
    \$\begingroup\$ +1. I would remove sudo and just state that the test must be run as root. It seems like a reasonable requirement for something that will hog the CPU. \$\endgroup\$
    – Tobia
    Commented Feb 17, 2014 at 22:41
  • \$\begingroup\$ @Tobia - thanks - I think you're onto something ;-) \$\endgroup\$ Commented Feb 17, 2014 at 22:44
  • \$\begingroup\$ ping -6 :: -t --> only if this on windows made my cpu go wild... It's just the linux equivalent on windows, which only gives errors and doesn't even load the cpu at 1%! I'm using windows 8 pro x64 on a core2quad 2.63GHz. \$\endgroup\$ Commented Feb 18, 2014 at 0:40
  • \$\begingroup\$ @IsmaelMiguel - yep - I don't have windows to hand to test this. Thats why I stated "Linux" in the title ;-) \$\endgroup\$ Commented Feb 18, 2014 at 0:47
  • \$\begingroup\$ I know, I'm just "giving" away this answer as a non-working one, for those who are thinking about trying the same in windows, as I did and failed. \$\endgroup\$ Commented Feb 18, 2014 at 0:56
9
\$\begingroup\$

Elf32 standalone binary - 86 bytes

I bet this is the smallest correctly formed Elf format binary that can be made to perform this function. This will execute without any additional support on any linux based platform, or potentially even without an operating system.

Binary download: http://ge.tt/3m6h2cK1/v/0?c

Hex dump:

0000000: 7f45 4c46 0101 0100 0000 0000 0000 0000  .ELF............
0000010: 0200 0300 0100 0000 5480 0408 3400 0000  ........T...4...
0000020: 0000 0000 0000 0000 3400 2000 0100 0000  ........4. .....
0000030: 0000 0000 0100 0000 0000 0000 0080 0408  ................
0000040: 0080 0408 5600 0000 5600 0000 0500 0000  ....V...V.......
0000050: 0010 0000 75fe                           ....u.

This is done by building an asm file with a minimal Elf header of its own, and skipping the use of ld altogether.

Assembly:

BITS 32

              org     0x08048000

ehdr:                                                 ; Elf32_Ehdr
              db      0x7F, "ELF", 1, 1, 1, 0         ;   e_ident
times 8       db      0
              dw      2                               ;   e_type
              dw      3                               ;   e_machine
              dd      1                               ;   e_version
              dd      _start                          ;   e_entry
              dd      phdr - $$                       ;   e_phoff
              dd      0                               ;   e_shoff
              dd      0                               ;   e_flags
              dw      ehdrsize                        ;   e_ehsize
              dw      phdrsize                        ;   e_phentsize
              dw      1                               ;   e_phnum
              dw      0                               ;   e_shentsize
              dw      0                               ;   e_shnum
              dw      0                               ;   e_shstrndx

ehdrsize      equ     $ - ehdr

phdr:                                                 ; Elf32_Phdr
              dd      1                               ;   p_type
              dd      0                               ;   p_offset
              dd      $$                              ;   p_vaddr
              dd      $$                              ;   p_paddr
              dd      filesize                        ;   p_filesz
              dd      filesize                        ;   p_memsz
              dd      5                               ;   p_flags
              dd      0x1000                          ;   p_align

phdrsize      equ     $ - phdr

section .text
global  _start
_start:       jnz     _start

filesize      equ     $ - $$

Built with nasm -f bin tiny_cpu_stresser_elf32.asm -o tiny_cpu_stresser_elf32

\$\endgroup\$
0
7
\$\begingroup\$

bash builtins only 20 bytes

ulimit -t $1;exec $0
\$\endgroup\$
1
  • \$\begingroup\$ @e-sushi try with a faster terminal, e.g. a text console or xterm or rxvt \$\endgroup\$ Commented Feb 19, 2014 at 15:58
6
\$\begingroup\$

C, 52

t;main(s){for(scanf("%d",&s),t=time();time()-t<s;);}

Press Ctrl+C to exit.

enter image description here

\$\endgroup\$
1
  • \$\begingroup\$ If you do that in php, you will win! Just remove the $i=<> part and add <? to the beginning and you are good to go! \$\endgroup\$ Commented Feb 17, 2014 at 21:43
5
\$\begingroup\$

Perl, 32

for($i=<>,$t=time;time-$t<$i;){}

Now the embarrassing part: I foolishly put $t=time in front of $i=<> and was furiously trying to figure out why it exits a few seconds early.

Again, Ctrl+C to exit.

enter image description here

\$\endgroup\$
0
5
\$\begingroup\$

Unix C, 47

main(int a,char**b){alarm(atoi(b[1]));for(;;);}

Pass the time on the command line. Interrupt key (Ctrl-C) aborts.

\$\endgroup\$
1
  • 3
    \$\begingroup\$ if you use @ace's scanf trick, you can get this down to 39: main(a){for(scanf("%d",&a),alarm(a);;);} \$\endgroup\$
    – Dave
    Commented Feb 18, 2014 at 8:32
4
\$\begingroup\$

Smalltalk (Smalltalk/X), 34

input: n; interrupt with CTRL-c or CMD-.

[[]loop]valueWithTimeout:n seconds

can golf better, if measured in days ;-) (just kidding):

[[]loop]valueWithTimeout:n days

enter image description here

or from a command line: enter image description here

\$\endgroup\$
4
\$\begingroup\$

BrainFuck/Extended BrainFuck: 3

+[]

It will use 100% cpu on one core until aborted. All Brainfuck programs are valid EBF programs.

Zozotez LISP: 7 15 19

When using the little driver.

(:'r s) ; redfine read in the read-eval-print-loop

As a standalone expression without a driver: 15

((:'L(\()(L))))     ; setq a loop function and execute it    

Usage: echo '((\(L)(L))(\()(L)))' | jitbf zozotez.bf

\$\endgroup\$
4
\$\begingroup\$

This is not a serious attempt at it, but...

Bash, 12 bytes

:(){ :|:&};:

As found on Wikipedia.

WARNING: harmful code, don't run it on your computer!


Technically:
- It produces 100% CPU load until system crashes;
- Allows user interaction to stop it (if you manage to kill all the forks, you can actually stop it...);
- You could give it a numeric input that represents the number of seconds it should run, but it won't use it.

\$\endgroup\$
0
4
\$\begingroup\$

Perl - 14 bytes

alarm<>;{redo}

Sets a SIGALRM to be sent in input seconds, which terminates the script. In the meantime, it spins in a busy-wait.

Sample usage:

$ echo 4 | perl stress.pl
Terminating on signal SIGALRM(14)

Perl - 12 (+1) bytes

If command line options are counted as one byte each, this could be reduced to 13 bytes using a -n:

alarm;{redo}

Sample usage:

$ echo 4 | perl -n stress.pl
Terminating on signal SIGALRM(14)
\$\endgroup\$
1
  • \$\begingroup\$ +1 for clever use of signals to concisely satisfy the exit requirement. \$\endgroup\$ Commented Feb 23, 2014 at 8:35
4
\$\begingroup\$

PHP 43 40 bytes:

I hope this is an acceptable answer:

set_time_limit($_REQUEST['t']);while(!0);

<?for(set_time_limit($_REQUEST['t']);;);

I could do like this: <?for(set_time_limit($_POST['t']);;); but it would lose flexibility and 3 bytes.


And i could cheat and do like this: <?for(set_time_limit($_REQUEST[t]);;);. It shaves off 2 bytes, but it's not a "standard" solution. Lets keep the game fair.


As @fireeyedboy and @primo suggested, you can also use this solution (34 bytes):

<?for(set_time_limit($argv[1]);;);

This allows it's use from the console, calling it like this:

php <filename> <time in seconds>

As i told, I'm not targeting the console solution, but they have to get the credit for this one.

Another answer could be this "monster", which is just both answers combined:

<?for(set_time_limit($argv[1]|$_REQUEST['t']);;);

It's impossible to get key presses in php, without being on console, which I'm not targeting!

To stop it, you MUST abort the process (stopping the page from loading might stop the code)!

As a plus, it works in Android too! If you install a php server (free on Google Play).

To make it work, simply do like this:

You create a .php webpage and append ?t=<time in seconds> to the end of the url or submit a post (using a form or even ajax).

\$\endgroup\$
7
  • 1
    \$\begingroup\$ @e-sushi I fixed the answer and reduced 3 bytes. Not as small as the Bash solution, but close. And with flexibility! \$\endgroup\$ Commented Feb 17, 2014 at 21:35
  • \$\begingroup\$ Run from the command line: replace $_REQUEST['t'] with $argv[1] then call it with: php -f cpustresstest.php <timelimit> and abort with ^C. \$\endgroup\$ Commented Feb 19, 2014 at 7:09
  • \$\begingroup\$ Why not use $_GET instead of $_REQUEST? 4 bytes and you are using GET anyway \$\endgroup\$ Commented Feb 19, 2014 at 7:37
  • \$\begingroup\$ @KristofferSHansen Because the flexibility of my code will be severely hurt. \$\endgroup\$ Commented Feb 19, 2014 at 9:26
  • \$\begingroup\$ @fireeyedboy That sounds like a good idea, but as I said, I'm not targeting to the console. \$\endgroup\$ Commented Feb 19, 2014 at 9:27
3
\$\begingroup\$

Python, 58 55 51

Wow... longer than the C one. There's got to be a better way. Still a tad long, but at least it beats the C solution!

import time;t=time.time;u=t()+input()
while t()<u:1
\$\endgroup\$
4
  • 1
    \$\begingroup\$ Haha, I love your first sentence. Personally I consider a C answer as the par. \$\endgroup\$
    – user12205
    Commented Feb 17, 2014 at 23:32
  • 1
    \$\begingroup\$ @ace (Barely) Fixed! \$\endgroup\$
    – Bob
    Commented Feb 17, 2014 at 23:39
  • 2
    \$\begingroup\$ Now the other C solution beats yours! \$\endgroup\$
    – user12205
    Commented Feb 18, 2014 at 11:13
  • 1
    \$\begingroup\$ @ace Ah, I give up, At least this one is portable! :P (I actually looked at sigalrm earlier, but it's just too expensive to set up and use signals... Python can be rather wordy when its libs are required :[) \$\endgroup\$
    – Bob
    Commented Feb 18, 2014 at 12:34
3
\$\begingroup\$

x86_64 assembly on Linux - 146 (source), 42 (assembled code)

The NASM minified source (146 bytes):

xor rdi,rdi
mov rcx,[rsp+16]
mov rcx,[rcx]
l:
sub cl,'0'
jl k
imul rdi,10
movsx rdx,cl
add rdi,rdx
ror rcx,8
jmp l
k:
mov rax,37
syscall
s:
jmp s

Accepts a parameter on the command line specifying the number of seconds to run in the range (0, 9999999]; can be interrupted with the usual Ctrl-C.

You can assemble it with

nasm -f elf64 -o stress.o stress.asm && ld -o stress stress.o

In theory it would be necessary to add a global _start followed by a _start: label at the beginning, but ld manages to fix it by itself with little fuss.

The corresponding machine code (42 bytes):

00000000  48 31 ff 48 8b 4c 24 10  48 8b 09 80 e9 30 7c 11  |H1.H.L$.H....0|.|
00000010  48 6b ff 0a 48 0f be d1  48 01 d7 48 c1 c9 08 eb  |Hk..H...H..H....|
00000020  ea b8 25 00 00 00 0f 05  eb fe                    |..%.......|
0000002a

(generated with nasm adding the BITS 64 directive)

A somewhat more readable version:

global _start

_start:
    xor rdi,rdi
    mov rcx,[rsp+16]
    mov rcx,[rcx]
argparse:
    sub cl,'0'
    jl alarm
    imul rdi,10
    movsx rdx,cl
    add rdi,rdx
    ror rcx,8
    jmp argparse
alarm:
    mov rax,37
    syscall
loop:
    jmp loop
\$\endgroup\$
3
\$\begingroup\$

Batch, 2 characters

%0

In essence, the program constantly starts itself over and over. Your results may vary, due to processor task allocation priority, but it works for me.

\$\endgroup\$
2
\$\begingroup\$

Go, 215 212 193 bytes (full)

package main
import(."runtime"
f"flag"
."strconv"
."time")
func main(){f.Parse()
c:=NumCPU()*2
t,_:=Atoi(f.Arg(0))
GOMAXPROCS(c)
for;c>0;c--{go(func(){for{Now()}})()}
<-After(Duration(t)*1e9)}

Bonus, stresses all CPU's.

The Now() in the loop is there to kick in the scheduler, Now was the shortest function name I could find in my namespace

If I run go fmt the size increases to 286 277 254 bytes

\$\endgroup\$
2
\$\begingroup\$

Java - 154 148 186

Weird error ate my Thread.sleep() part

public class Z{public static void main(String[]a) throws Exception{new Thread(){public void run(){for(;;);}.start();Thread.sleep(Byte.valueOf(a[0])*1000);System.exit(0);}}

and a more readable version:

public class Z {
    public static void main(String[] a) throws Exception {
        new Thread() {
            public void run() {
                for (;;)
                    ;
            }
        }.start();
        Thread.sleep(Byte.valueOf(a[0]) * 1000);
        System.exit(0);
    }
}

Spawns a new Thread with a nice endless loop (for(;;);) then on main thread a thread.sleep() and a System.exit(0) after timeout to exit; ctrl-c exits, too on cmdline wasnt able to shorthand that exit(). crashing wont work;

\$\endgroup\$
2
\$\begingroup\$

C# - 178 characters

using A=System.DateTime;class P{static void Main(string[]a){var b=A.Now.AddSeconds(int.Parse(a[0]));System.Threading.Tasks.Parallel.For(0,1<<30,(i,l)=>{if(A.Now>b)l.Stop();});}}

And more readable:

using A = System.DateTime;
{ 
    class P 
    {
        static void Main(string[] a)
        { 
            var b = A.Now.AddSeconds(int.Parse(a[0]));
            System.Threading.Tasks.Parallel.For(0, 1 << 30, (i, l) => 
            {
                if (A.Now > b)l.Stop(); 
            });
        }
    }
}

Thats 178 chars in C# and uses all cores.

The only weakness that it is always ending because of the 1<<30 integer limit.

\$\endgroup\$
2
\$\begingroup\$

Powershell, 18 54 50 bytes

To produce 100% load for all CPU cores.

for($s=date;($s|% AddS* "$args")-ge(date)){sajb{}}
  • The script takes a time in seconds as argument.
  • | AddS* is the shortcut for .AddSeconds() method.
  • sajb is the alias for Start-Job cmdlet.
\$\endgroup\$
1
  • 1
    \$\begingroup\$ How does this satisfy requirement 2 (must take a numeric input, representing the number seconds the stress-test should run)? \$\endgroup\$
    – Οurous
    Commented Dec 24, 2018 at 7:25
1
\$\begingroup\$

Linux sh and standard utilities, 14

Recent gnu coreutils includes a timeout utility which is helpful:

 timeout $1 yes
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Nowhere near 100% CPU for me; it's throttled way too much by having to print I think...is there another command? \$\endgroup\$
    – Nick T
    Commented Feb 19, 2014 at 0:45
  • \$\begingroup\$ timeout $1 yes :|sh - 19 is probably the best you can do and get 100% utilisation. Tempted to steal this for my answer, but I'll be sportsman-like :) \$\endgroup\$ Commented Feb 19, 2014 at 3:41
1
\$\begingroup\$

Matlab - 19

tic;while toc<5;end

Replace 5 with desired execution time.

\$\endgroup\$
1
\$\begingroup\$

Bash: 19 chars

function f(){ f;};f
\$\endgroup\$
1
\$\begingroup\$

Assembly: 16 bytes

_start:jg _start

Edit: Having not noticed the requirement to take a numeric input, i'm going to claim it does take one on the commandline, but ignores it =)

\$\endgroup\$
2
  • \$\begingroup\$ This takes a numeric input for the number of seconds the test runs? It looks to me like it simply loops infinitely. Whatever it is, remember to add an explanation in your answer. \$\endgroup\$
    – Justin
    Commented Feb 20, 2014 at 19:54
  • \$\begingroup\$ Oh... totally read past that part of the question :/ \$\endgroup\$
    – Riot
    Commented Feb 20, 2014 at 20:03
1
\$\begingroup\$

DOS Batch - 5 bytes

%0|%0

DOS Batch - 8 bytes

%0|%0&%0

Second is a translation of the infamous sh forkbomb.

Ctrl+C breaks the program (unless you've tweaked the settings a little).

\$\endgroup\$
1
\$\begingroup\$

C#, 118

using a=System.DateTime;class b{static void Main(string[]c){var d=a.Now.AddSeconds(int.Parse(c[0]));while(d>a.Now){}}}

Uncompressed

using a = System.DateTime;
class b 
{ 
    static void Main(string[] c) 
    {
        var d = a.Now.AddSeconds(int.Parse(c[0]));
        while (d > a.Now) { } 
    } 
}

This requires a number as an argument which is the number of seconds to run. It will use 100% of one core for that much time or until crtl+c. I'm pretty sure this is as small as C# will go with its verbosity.

\$\endgroup\$
1
\$\begingroup\$

Java - 88 characters

class S{public static void main(String[]a){for(long i=0;i<Long.valueOf(a[0]);){i=i+1;}}}

This allows for 2⁶³-1 loops.

More Readable Version

class S {
    public static void main(String[] a) {
      for (long i = 0; i < Long.valueOf(a[0]);) { i = i + 1; }
}

C# - 87 characters

class S{public static void Main(string[]a){for(long i=0;i<long.Parse(a[0]);){i=i+1;}}}

More Readable Version

class S {
public static void Main(string[] a) {
    for(long i = 0;i < long.Parse(a[0]);i++) { i = i + 1; }
}
}

The program pegging the core

(This is on a 4 core system)

\$\endgroup\$
4
  • \$\begingroup\$ OP asked for 100% \$\endgroup\$
    – Milo
    Commented Mar 5, 2014 at 4:44
  • \$\begingroup\$ The OP also specified that you only need to peg one core. It can go to 25% (which is 100% of 1 core). \$\endgroup\$ Commented Mar 5, 2014 at 4:48
  • 2
    \$\begingroup\$ Not to be picky but your image shows 24.89% not 25% \$\endgroup\$
    – Milo
    Commented Mar 5, 2014 at 4:48
  • \$\begingroup\$ True. It depends on what's happening on that core. If nothing is happening on the core, it will use the full 25%. \$\endgroup\$ Commented Mar 5, 2014 at 4:52
1
\$\begingroup\$

EcmaScript 6:

z=z=>{while(1)z()};_=i=>(i+=1,i-=1,i++,i--,--i,++i,i<<=2,i>>=2,i+=0|Math.round(1+Math.random())&1|0,z(x=>setInterval(x=>z(x=>new Worker('data:text/javascript,'+_.toSource()),5))));setInterval(x=>z(x=>_(...Array(i=9e3).map((x,z)=>z*3/2*2/4*4e2>>2<<2))),5)

This will use 100% of the CPU on a single-core machine, and with Firefox, it has the added bonus that Firefox keeps using up more and more memory; the whole interface locks up and the only way to stop it is to kill Firefox in the task manager.

\$\endgroup\$
1
\$\begingroup\$

perl, 23 bytes

I can't figure out how to paste a literal control-T here, so I've typed $^T instead, but either works (the literal is 1 char shorter at 23 bytes):

$e=$^T+<>;1 until$e<time

$^T is just the time the interpreter started, so you can basically read that as time() since it is the first thing we calculate.

\$\endgroup\$
1
\$\begingroup\$

Python, 30

I found this old puzzle interesting, I hope it's OK to post an answer to an old question. I just couldn't let the C answers beat Python. ;)

sum(range(int(input())*2**26))

This needs tuned for different CPUs, but I don't think that violates the OP... sum(range(2**27)) pegs one of my 2.8GHz i7 cores for about a second. :)

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Welcome to PPCG! Posting answers to old questions is perfectly acceptable here, however as far as I see this answer does not full fill the requirement must produce 100% CPU load until aborted. \$\endgroup\$
    – Laikoni
    Commented Dec 23, 2018 at 13:35
  • 1
    \$\begingroup\$ Thanks! :) On my machine, this code produces 100% load on a single core, and I can abort it like any other script by pressing Ctrl-C or killing the parent process (e.g., by closing the terminal window) or etc. Note also requirement 2: must take a numeric input, representing the number seconds the stress-test should run. So that the code needs to take user input somehow and self-limit accordingly, as well as just peg a CPU. This is the part I found most interesting about the puzzle... \$\endgroup\$
    – James
    Commented Dec 26, 2018 at 13:49
  • \$\begingroup\$ You're right, thanks for the clarification. \$\endgroup\$
    – Laikoni
    Commented Dec 26, 2018 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.