[Question] speed of imwrite

18 views (last 30 days)
Jhen-Si Chen
Jhen-Si Chen on 23 Jan 2013
I am using imwrite to write the .bmp file, and wondering some information about its speed.
I was writing 1024 x 768 bmp, which is 768 KB, and matlab finished the writing on my computer with about 8 ms, which is equal to 93 MB/s. I have tested the writing speed of my hard disk, which is about 100 MB/s. So, it is fair.
And then, I used the Ram disk (there are softwares supportting to use the ram as an extra temporal hard disk while the computer is on.). The writing speed of it is about 3 GB/s. (I use some hard disk testing software to measure.) However, when I use matlab to write the file in that Ram disk, the necessary time is still about 8 ms. It seems to me that matlab is limited to something else, not just the hard-disk physical limitation.
In this case, I am wondering how could I write it with a higher speed on the ram disk? since its physical limitation is much higher. Could anyone answer me?
Many thanks

Answers (3)

Walter Roberson
Walter Roberson on 23 Jan 2013
If speed during main program execution is the critical factor, then consider writing out the images as binary files using fwrite(), and then at a later time when main program execution is finished, do a pass that fread() and imwrite() them.
  4 Comments
Jhen-Si Chen
Jhen-Si Chen on 24 Jan 2013
I just tested it, and the speed of fwrite and imwrite are very similar, the difference is less than 5%, and sometimes fwrite is even slower.
So did you imply that imwrite does some other actions and not just writing? I thought imwrite should simply write the header and the matrix data, fairly straight forward.
Walter Roberson
Walter Roberson on 24 Jan 2013
imwrite() needs to do image compression for most image formats.

Sign in to comment.


Jhen-Si Chen
Jhen-Si Chen on 24 Jan 2013
and actually, my main point is, the data should be past to the ram disk (the speed of it should be 3GB/s).
If the writing is done in this structure: main memory (matlab workspace) > ram disk, then it should be much quicker than writing on the hard disk, and I think my CPU should be able to be over than 100 MB/s.
Unless the writing of imwrite is done in a way that main memory (matlab site) > some buffer (maybe in the hard disk) > ram disk. In this case, the speed is limited by the hard disk physical speed, which is about 100 MB/s for my hard disk.
If it is in this case, I am wondering how should I get rid of the buffer stage. And if it is not in this case, and what happened during the imwrite?
  2 Comments
Image Analyst
Image Analyst on 24 Jan 2013
Edited: Image Analyst on 24 Jan 2013
This is not an answer and should have been added to your comment above.
So why don't you write directly to your ramdisk then? Why use the hard disk during image acquisition? Originally you said you tried this, now you're saying you are using imwrite to go to "some buffer maybe in the hard disk" - well, what is the file name in that call to imwrite that you're giving it? Is it a filename on the ramdisk?
Jhen-Si Chen
Jhen-Si Chen on 24 Jan 2013
yes, you are right, so I shouldn't have put that in the answer. Sorry for this mistake.
And actually, I did directly write the file to my ram disk. (well, at least my code was written in this way). I didnt say I write it to some buffer, what I said is I was suspecting that is what the imwrite did when it is writing. I got this assumption according to the actual time I spent, even if I have directed the file path to the ram disk.
And yes the filename (and its path) is on (to) my ram disk.

Sign in to comment.


Jan
Jan on 24 Jan 2013
When you write 768kB to a hard disk, the data is stored in the RAM also at first, e.g. in the write cache of the harddisk. It is not trivial to measure the time, which is required until the data are written physically to the disk.
  3 Comments
Walter Roberson
Walter Roberson on 24 Jan 2013
No, the above applies when writing to hard disk.
Jan
Jan on 24 Jan 2013
@Jhen-Si Chen: No, this means that writing small files, e.g you <1MB file, to a hard disk is at first buffered in DRAM, such that the processor can proceed its work until the slow hard drive has written the data to the disk physically.
Therefore I think that the similarity of 93 MB/s for IMWRITE and 100 MB/s for the hard disk speed is a pure accident. The timing with the RAM disk seems to be a further argument for this claim.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!