Let's say I have two bash files. The first one is called diskFile.bash:
for i in {1..10000}
do
file=$(mktemp)
cat > $file <<- "SIGN"
"Hello World"
SIGN
done
echo "finished"
And the second one is called ramFile.bash:
for i in {1..10000}
do
file=$(mktemp -p /dev/shm/)
cat > $file <<- "SIGN"
"Hello World"
SIGN
done
echo "finished"
On Linux, files created inside /dev/shm are files inside the RAM memory of the system. But if I try executing the first file with time bash diskFile.bash, I get:
finished
15.56user 5.74system 0:20.25elapsed 105%CPU (0avgtext+0avgdata 6324maxresident)k
And with time bash ramFile.bash:
finished
15.20user 5.37system 0:19.45elapsed 105%CPU (0avgtext+0avgdata 6380maxresident)
The difference of time doesn't look like a significant one considering /dev/shm should be using RAM memory. Why creating temporary files inside /dev/shm is not faster than creating temporary files inside /tmp? Is there any way of speeding up the process of creating files using bash?