2-Cent Tips
2-cent tip: Getting the "true" transfer rate during disk I/O benchmark
Mulyadi Santosa [mulyadi.santosa at gmail.com]
Sun, 24 Feb 2008 15:23:23 +0700
So say you want to test how fast your disk does writing operation. You might do this:
dd if=/dev/zero of=/mount/point/of/your/partition/testfile bs=4K count=256M
It will write 1GB file to the target partition. But one thing you might don't know is that the filesystem system do it in so called "write back" style. In this mode, data actually transit in temporary cache before actually being flushed to the disk. As the result, you get faster I/O speed.
How to get the real number then? Try to add "oflag=sync" as the option of dd. Then repeat the test, possibly by combining "dd" and "time" to get real/sys/user time statistic. This way, writing will be done synchronously i.e a block of data will be pushed to the disk before next blocks are going to be written.
Other benchmark program also provide you the same mode. Check the related documentations so you really know the meaning of the numbers you get. Also, as the rule of thumb, write something bigger than your L2 (or L3, if you have it) cache size, so I/O is done mostly between RAM and the disk, not originated CPU cache. Cache is thousands time faster than RAM, which also gives you another layer of "speed illusion".
[ Thread continues here (3 messages/6.82kB) ]
2-cent Tip: Editing Perl scripts in Vim
Ben Okopnik [ben at linuxgazette.net]
Sun, 3 Feb 2008 10:50:25 -0500
The longer I use Vim, the more ways I find to make my life easier. This tip comes courtesy of Andy Lester's entry in the "Mechanix" blog (http://perlbuzz.com/mechanix/2008/01/vim-tricks-for-perl.html), where he shows a nifty trick for looking up Perl documentation for both functions and modules. I used to have it set up for just the former, but my lookup method is a little fancier - I open a scratch buffer in another window so you can look at both the docs and your code at the same time. So, combining the two results in the following:
autocmd FileType perl nmap K "zyiw<c-W>n:set buftype=nofile<CR>:r! \perldoc -tf '<c-R>z' 2>/dev/null <bar><bar> perldoc '<c-R>z'<cr>gg
(Yes, the 'escape' slash does go on the second line.)
Now, whenever your cursor is on a perl function or a module name, simply hit 'shift-k' (the standard vi/vim "lookup" key), and you'll get the docs.
-- * Ben Okopnik * Editor-in-Chief, Linux Gazette * http://LinuxGazette.NET *
[ Thread continues here (5 messages/6.06kB) ]
2-cent tip: Convert your mp3 files into ogg
Mulyadi Santosa [mulyadi.santosa at gmail.com]
Sat, 26 Jan 2008 21:54:43 +0700
First, why? Easy, because mp3 is a patented format and ogg is an open source format. So, to guarantee your peace of mind (like what Cattano said to Frank Lucas in "American Gangster" ), use ogg.
To do it, first I assume you have mpg123 (http://www.mpg123.de/) installed and the binary is located in searchable path (check your $PATH).
Your mp3 files probably contain spaces, so use this script:
#!/bin/bash for b in *; do ( cd $b; for a in *; do mv -v "$a" $(echo $a | sed s/\ /\_/g); done ) ; done
The script assumes your working directory has subdirectories that holds the mp3 files (think of it as albums). Outer loop lists the directories and inner loop "cd" into them and rename the files inside so they don't contain spaces anymore.
Finally, the real piece of work:
#!/bin/bash for b in *; do ( cd $b; for a in *; do test=$(echo $a | cut -f1 -d\.).wav ; mpg123 -v -w $test "$a"; oggenc $test ; rm -fv $test ; rm -fv "$a" ; done ); done
In short, the script loops over your collections. It uses mpg123 to convert your mp3s into wavs. Then, oggenc converts it as ogg. The wav is then deleted since we don't need it anymore. Why create wav 1st, you might ask? Well, i tried to pipe mpg123 directly to oggenc but somehow it didn't work (at least in my case), so that's my workaround.
regards,
Mulyadi.
[ Thread continues here (5 messages/8.93kB) ]