I have a function that does IO/computation. I made a demo function which copies ~300MB from here to there. If I run it in a thread which I immediately join, it is much slower than if I run it without a thread. I checked with:
def cp
start = Time.now
FileUtils.cp_r("C:/tmp", "C:/tmp1")
fin = Time.now - start
p fin
end
Comparing these:
cp
Thread.new{cp}.join
the first cp
call is always two to four times faster than the threaded call. The same happens if I do
cp
Thread.new{cp}
sleep 200
I heard about GIL, etc., but here, only one thread runs at a time, so no race for running time. Any ideas on how I can make it faster or why that is happening?