Skip to content

Instantly share code, notes, and snippets.

@zloster
Created November 17, 2016 15:24
Show Gist options
  • Save zloster/bcf82dd558fc5733851455180fa37a49 to your computer and use it in GitHub Desktop.
Save zloster/bcf82dd558fc5733851455180fa37a49 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:

688471 instructions

--@--:~$ uname -a
Linux 3.13.0-101-generic #148-Ubuntu SMP Thu Oct 20 22:09:17 UTC 2016 i686 i686 i686 GNU/Linux
--@--:~$ sudo perf stat echo test
test

 Performance counter stats for 'echo test':

          0,898550 task-clock (msec)         #    0,633 CPUs utilized          
                 2 context-switches          #    0,002 M/sec                  
                 1 cpu-migrations            #    0,001 M/sec                  
               151 page-faults               #    0,168 M/sec                  
           1848617 cycles                    #    2,057 GHz                    
   <not supported> stalled-cycles-frontend 
   <not supported> stalled-cycles-backend  
            688471 instructions              #    0,37  insns per cycle        
            126235 branches                  #  140,487 M/sec                  
     <not counted> branch-misses           

       0,001418434 seconds time elapsed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment