I asked myself the same question. Is /dev/shm/ faster than my home directory or /tmp?
I distrust the bash-loop test. Someone else suggested that this should be done in C/C++.
This is my test:
We have a large server with 3TB RAM, which is currently running under full load, so it is not as fast as it could be. But the background load was 100% stable during this test. The jobs on the server read and write to /dev/shm as well as to the HDD.
First "df /tmp" gives me:
tmpfs          1585333764  976564 1584357200    1% /tmp
and "df /dev/shm" gives me:
tmpfs          1585333764  977168 1584356596    1% /dev/shm
The tmpfs tells me that both are in RAM.
The disc I did this test on has this space left:
/dev/sdb1        60T     52T  4,9T   92%
Code I used to run benchmark test:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
  const int N=1000000000;
  char * data    = new char [N];
  char * data_in = new char [N];
  
  string   filename="out.txt";
//  string   filename="/tmp/out.txt";
//  string   filename="/dev/shm/out.txt";
  ofstream os(filename.c_str());
  for (int i=0; i<N; ++i)
    data[i] = 'A'+ i%20;
  os.write(data, N);
  os.close();
  ifstream is(filename.c_str());
  is.read(data_in, N);
  unsigned long sum;
  for (int i=0; i<N; ++i)
    sum += (unsigned char)data_in[i];
  cout << sum << endl;
}
I compiled 3 versions using the different output file paths, all with g++ -O3. The compiler I used is:
gcc-Version 5.3.1 20160406 (Red Hat 5.3.1-6) (GCC)
The compiler is a bit old, but this should not influence this test, I think.
The HDD are in a huge RAID5, fast SAS, no SSD. The RAID will slow down writing to the disc a bit.
Results:
writing and reading to disc:
real    0m5.739s
user    0m1.602s
sys     0m2.541s
Writing and reading to tmp:
real    0m3.669s
user    0m1.645s
sys     0m2.009s
Writing and reading to /dev/shm:
real    0m3.639s
user    0m1.633s
sys     0m1.991s
I repeated this a few times. The results are highly consistent.
So writing to disc is certain a bit slower than writing to the in memory RAM (/tmp or /dev/shm).
The values are so close together that I think everyone has to test this for her/his system. The fact that I have a RAID could influence the result, but in the end, this is what I want to compare.
So the answer/conclusion that I/O to /dev/shm is slower than to an HDD is not the general answer.
     
    
/tmpis on disk? (It’s commonly in memory now.)$HOMEand I've executed the code withfile=$(mktemp -p /home/myuser/tmp)(to be sure that this folder is in disk)... I still got15.58user 6.41system 0:20.91elapsed 105%CPU (0avgtext+0avgdata 6392maxresident)kas result...timecommand.sync? The/tmpfiles are probably only in the page cache (in memory) for the duration of your test./tmp.) How are you measuring / observing “space on [your] hard disk”? (2) This is not really a question about bash, and I doubt that it will be answered with bash knowledge.