title: why splice() performs so bad on my system?
body: <h2><strong>I want to test the performance of the splice() syscall. I compare it with the traditional read/write.</strong></h2>
  
  <pre><code>/* wr.cpp 
   * it use read/write
   */
  #include  &lt;sys/types.h&gt;
  #include  &lt;sys/stat.h&gt;
  #include  &lt;fcntl.h&gt;
  #include  &lt;unistd.h&gt;
  
  #define BUF_SIZE 4096
  
  int main(int argc, char *argv[])
  {
      char buf[BUF_SIZE];
      int in = open("1.rmvb",O_RDONLY);
      int out = open("1.cp.rmvb",O_WRONLY|O_CREAT,0766);
  
      ssize_t nread;
      while( (nread = read(in,buf,BUF_SIZE)) &gt; 0 )
      {
          write(out,buf,nread);
      }
  
      return 0;
  }
  </code></pre>
  
  <p>//</p>
  
  <pre><code>/* splice.cpp 
   * it use splice
   */
  #ifndef _GNU_SOURCE
  #define _GNU_SOURCE
  #endif
  
  #include  &lt;sys/types.h&gt;
  #include  &lt;sys/stat.h&gt;
  #include  &lt;fcntl.h&gt;
  #include  &lt;unistd.h&gt;
  
  #define BUF_SIZE 4096
  
  int main(int argc, char *argv[])
  {
      char buf[BUF_SIZE];
      int in = open("1.rmvb",O_RDONLY);
      int out = open("1.cp.rmvb",O_WRONLY|O_CREAT,0766);
  
      ssize_t nread;
      while( (nread = splice(in,NULL,p[1],NULL,BUF_SIZE,0)) &gt; 0)
              splice(p[0],NULL,out,NULL,BUF_SIZE,0);
  
  
      return 0;
  }
  </code></pre>
  
  <h2><strong>here is the result:</strong></h2>
  
  <p><img src="https://i.stack.imgur.com/yGAcD.png" alt="enter image description here"></p>
  
  <h2><strong>It seems that spilce() didn't improve the performance and didn't reduce the CPU time. Why? My kernel version is 2.6.35-28, ubuntu 10.10.</strong></h2>