You could create a "ram disk". Tmpfs is virtual memory but it will be in ram most of the time (except when memory is over-committed then it gets paged out like any other memory).
I add these two lines to /etc/fstab.
Code: Select all
tmpfs /tmp tmpfs defaults,noatime 0 0
tmpfs /var/log tmpfs defaults,noatime,size=16m 0 0
So you could save your files to /tmp. Here /tmp will be half the size of memory, 2GB.
However, I must say that you may not see much of a speed-up as the disk cache on Linux is remarkably effective.
When you write a file, it is always written to memory. (The system will write it to the disk later which has all sorts of benefits).
A file frequently read will also be in memory as the system retains a copy of the file after you have read it.
Python is known to be very slow. If you want a performance increase, consider another language such as C or C++.