What can be done to make the executable files smaller? When we get the normal ELF file we can first strip it and then compress it in a way it will decompress during each run. We've got the binary file hello which prints hello world:
$ ls -l hello
-rwxr-xr-x 1 berdzi users 6230 2009-08-22 18:04 hello
It's 6230 bytes big. We will strip it with strip command. Strip removes all debugging symbols from the binary. They are very helpful when we want to debug the file with i.e. gdb, whereas they not necessary in normal use. Stripping them saves a lot of space:
$ strip hello
$ ls -l hello
-rwxr-xr-x 1 berdzi users 2748 2009-08-22 18:09 hello
Now the file has only 2748 bytes. To make it smaller we can use gzexe. It will compress the file in place - it will be decompressed while each execution. This saves extra bytes increasing runtime. Let's see:
$ gzexe ./hello
./hello: 53.9%
$ ls -l hello
-rwxr-xr-x 1 berdzi users 2092 2009-08-22 18:12 hello
This will create two files: hello and hello~ where the second one is the original file and if we sure the compressed version is ok, we can remove the source. We can always decompress the compressed file with -d switch.
Let's compare the execution time of compressed file and the original:
$ time ./hello~
Hello world
real 0m0.004s
user 0m0.000s
sys 0m0.004s
$ time ./hello
Hello world
real 0m0.066s
user 0m0.016s
sys 0m0.040s
This particular binary executes 16 times slower (in this case in almost unnoticable).
Showing posts with label files. Show all posts
Showing posts with label files. Show all posts
Saturday, August 22, 2009
Sunday, August 16, 2009
Mass files renaming
Ever needed to change the extensions of the multiply files from one to the other? If you i.e. want to change all the files ended by .php3 to .php you could use the following command:
$ ls -d *.php3 | sed 's/\(.*\).php3$/mv "&" "\1.php"/' | sh
What we use here is sed replacing the part of the string (thanks to regular expression) with mv command and piping it to sh to which executes it. The detailed explanation of this process can be found here.
$ ls -d *.php3 | sed 's/\(.*\).php3$/mv "&" "\1.php"/' | sh
What we use here is sed replacing the part of the string (thanks to regular expression) with mv command and piping it to sh to which executes it. The detailed explanation of this process can be found here.
Subscribe to:
Posts (Atom)