문제

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

Ruby Script VS to Linux cp command

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!

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top