How many instructions to print Hello World (#100DaysToOffload Day7)

So this was supposed to go up yesterday but i passed out so here it is late.

About a week ago i saw a post talking about the (over)complexity of technology that keeps getting more and more complex in some ways seemingly to justify it's own complexity. In the process the fact that it took over 600k instructions to print the word “test” on a terminal window was pointed out. Since this was from 4 years ago i wondered how much that had changed since.

So here is the answer on my system.

First a little system info:

➤ cat /proc/cpuinfo | grep "model name"
model name : AMD Ryzen 5 2600X Six-Core Processor
➤ uname -a
Linux thebeach 5.6.8-artix1-1 #1 SMP PREEMPT Wed, 29 Apr 2020 18:45:03 +0000 x86_64 GNU/Linux

Now the test

➤ sudo perf stat echo "Hello World"
Hello World

 Performance counter stats for 'echo Hello World':

              0.54 msec task-clock                #    0.478 CPUs utilized          
                 0      context-switches          #    0.000 K/sec                  
                 0      cpu-migrations            #    0.000 K/sec                  
                62      page-faults               #    0.115 M/sec                  
         2,157,767      cycles                    #    3.999 GHz                    
           275,729      stalled-cycles-frontend   #   12.78% frontend cycles idle   
           169,688      stalled-cycles-backend    #    7.86% backend cycles idle    
           877,604      instructions              #    0.41  insn per cycle         
                                                  #    0.31  stalled cycles per insn
           187,115      branches                  #  346.745 M/sec                  
     <not counted>      branch-misses                                                 (0.00%)

       0.001129028 seconds time elapsed

       0.000000000 seconds user
       0.001178000 seconds sys

So there you have it 877,604 instructions to echo “Hello World”. I wont pretend to understand computer at that low level but that's an increase of 200k in 4 years to print a simple string. Part of this increase probably relates to mitigations for things like Spectre and Meltdown and some other “optimizations” over the years.

Well that is all for today.

Until tomorrow stay safe!