why second time cp command is faster

benchmarking, caching, linux, shell

Solution

This is because of page caching. Run `sync ; echo 3 > /proc/sys/vm/drop_caches` to make it slow again.

Further reading:

- http://jim.studt.net/depository/index.php/flushing-caches-for-benchmarking-in-linux

- https://superuser.com/a/319287/236874

Problem

When I execute `cp folder1 folder2 -rf`,for the first time it takes around 10 mins. But when it I execute the second command `cp folder1 folder3 -rf`, it takes around 1 min. `folder1` contains about 100 000 files. Why is there run time improvement for the second time?

Original source