Reputation: 30058
First, I know that when copying a file, if the buffer size is bigger, the copying process will be faster.
The following ruby script used to write line-by-line (i.e. size of buffer will depends on the line length):
input,output = ARGV[0], ARGV[1]
f_in = File.open input, "r"
f_out = File.open output, "w"
f_in.each {|line| f_out << line}
f_in.close
f_out.close
I've tried to copy a two files of size (300, 400 MBs), and found the above script is even faster than the cp Linux command, notably faster.
How this could happen? I suppose the cp
is fully optimized!
Upvotes: 1
Views: 616
Reputation: 113
It's probably due disk caches, try running
echo 3 > /proc/sys/vm/drop_caches
to clear up the cache before running your benchmark :)
my guess is that they do should be very, very close, ofcourse cp should start copying some miliseconds faster than ruby.
Upvotes: 3
Reputation: 1
It probably is happening because of the file system disk cache inside the kernel.
I'm sure that if you repeat several times a cp
command, timings will be different.
Use the time
command (as a prefix) to benchmark and repeat the test several times.
Upvotes: 3