This page is an archive of my old blog. Please visit DavidTucker.net for my current blog.
This site is no longer being maintained and commenting is disabled.

Creating Reference File Sizes

There are times (for benchmarking purposes) that you want to work with a file that is exactly 1 MB (for example). For a presentation next week I am testing how certain aspects of AIR perform with specific amounts of data. To accomplish this, I use one very powerful and dangerous command line utility (for both Mac and Linux): dd.

NOTE: This utility is very powerful, but you could truly wipe out most all of your hard drive and screw up your filesystem beyond repair. Don’t play with the dd command unless you know what you are doing.

One feature of dd is that you can create blocks of various sizes in your filesystem. The following command creates a 1 MB file block named 1MB.img:

dd if=/dev/zero of=1MB.img bs=1024 count=1024

The first option is if, this stands for ‘in-file’. This tells the command what you want to fill your new file with (in this case, /dev/zero will fill your file with zeros). The next option is of which is the name of the file you are exporting to. Even though the name here is 1MB.img, it has nothing to do with the size. The next two arguments determine the size of the new file. It states that you are creating blocks of 1024 bytes (the bs argument). The count argument states that you will be repeating this block 1024 times (which will equal 1MB).

This example can easily be expanded for other file sizes:

100 KB: dd if=/dev/zero of=100KB.img bs=1024 count=100
256 KB: dd if=/dev/zero of=256KB.img bs=1024 count=256
512 KB: dd if=/dev/zero of=512KB.img bs=1024 count=512
1 MB: dd if=/dev/zero of=1MB.img bs=1024 count=1024
10 MB: dd if=/dev/zero of=10MB.img bs=1024 count=10240
100 MB: dd if=/dev/zero of=100MB.img bs=1024 count=102400

Now, by utilizing these files, you can benchmark your application with standard file sizes.




Comments are closed.