title: Why is async code considered so much faster than synchronous?
body: <p>Why is synchronous code considered so much slower and more resource intensive than asynchronous code? For example nginx is considered faster than Apache and a NodeJS application is considered faster than a PHP application.</p>
  
  <p>Shouldn't it be trivial to compile synchronous code into an asynchronous equivalent? At least in JavaScript many people use libraries like <a href="https://www.npmjs.com/package/async" rel="nofollow">async</a> which help to write synchronous looking code.</p>
  
  <p><strong>Edit</strong>: Because of a question in the comments: Synchronous code like</p>
  
  <pre><code>byte[] buf = read(socket);
  do_something(buf);
  </code></pre>
  
  <p>is considered slow because the thread has to block for reading from <code>socket</code>, whereas</p>
  
  <pre><code>read(socket, function(buf) {
      do_something(buf);
  });
  </code></pre>
  
  <p>is considered fast. On the one hand the transformation should be trivial on the other hand both code has to wait for <code>read</code> just one time the thread has to be yielded whereas in the other case a return to the main event loop is necessary</p>