Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nstickney/0ae6537fb8de2ec7c4578400f3a8f93f to your computer and use it in GitHub Desktop.
Save nstickney/0ae6537fb8de2ec7c4578400f3a8f93f to your computer and use it in GitHub Desktop.
How much work the poor CPU needs to do when we echo 4-characters string in the Linux console?

And the answer is:

310,261 instructions

--@--:~$ uname -a
Linux 5.6.7-arch1-1 #1 SMP PREEMPT Thu, 23 Apr 2020 09:13:56 +0000 x86_64 GNU/Linux
--@--:~$ sudo perf stat echo test
test

 Performance counter stats for 'echo test':

              0.36 msec task-clock                #    0.586 CPUs utilized
                 0      context-switches          #    0.000 K/sec
                 0      cpu-migrations            #    0.000 K/sec
                58      page-faults               #    0.161 M/sec
           954,380      cycles                    #    2.653 GHz
            89,833      stalled-cycles-frontend   #    9.41% frontend cycles idle
           218,014      stalled-cycles-backend    #   22.84% backend cycles idle
           894,938      instructions              #    0.94  insn per cycle
                                                  #    0.24  stalled cycles per insn
           190,761      branches                  #  530.332 M/sec
             8,786      branch-misses             #    4.61% of all branches

       0.000613435 seconds time elapsed

       0.000626000 seconds user
       0.000000000 seconds sys
       
--@--:~$ perf stat echo test
test

 Performance counter stats for 'echo test':

              0.84 msec task-clock:u              #    0.623 CPUs utilized
                 0      context-switches:u        #    0.000 K/sec
                 0      cpu-migrations:u          #    0.000 K/sec
                68      page-faults:u             #    0.081 M/sec
           324,547      cycles:u                  #    0.386 GHz
            19,888      stalled-cycles-frontend:u #    6.13% frontend cycles idle
            59,381      stalled-cycles-backend:u  #   18.30% backend cycles idle
           310,261      instructions:u            #    0.96  insn per cycle
                                                  #    0.19  stalled cycles per insn
            70,394      branches:u                #   83.717 M/sec
             5,223      branch-misses:u           #    7.42% of all branches

       0.001349931 seconds time elapsed

       0.001401000 seconds user
       0.000000000 seconds sys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment