Ask HN: Why is something always faster the second time you run it
This is easily explained because the network needs to find a route, perform a DNS lookup, all that stuff. What my question is about though: Why does the same thing happen on a local server, or even localhost?
Write any PHP script, run it and measure the time in your browser, then run and measure again. It'll go much faster, even though memcache or anything like that is not enabled. If you make PHP (or whatever language) generate a random number to output, you'll see that you get the real output every time, so it's not cached.
The effect resets itself after a while (I'm not sure how long, I guess a few minutes). Is this something the CPU optimizes in its caches? Or is something stored in the RAM by either the webserver or the OS? Or does the file handle remain opened?
The effect works on every computer and system I've tried, and I'm really wondering what it could be. Perhaps someone knows?