Some Other Tools in UNIX:Image File Formats for Internet Applications and Performance Analysis and Profiling.
Image File Formats for Internet Applications
With the emergence of the multimedia applications, it became imperative to offer services to handle a variety of file formats. In particular, we need to handle image files to support both still and dynamic images. Below we give some well known mutimedia file formats which may be used with images.
JPEG is a compression standard specification developed by the Joint Photographic Engineering Group. There are utilities that would permit viewing the images in the .jpg files. Most JPEG compressions are lossy compressions. Usage of .jpg files is very popular on internet because it achieves a very high compression. In spite of being lossy, jpeg compression invariably works quite well because it takes into account some weaknesses in human vision. In fact, it works quite adequately with 24-bit image representations.
JPEG files are compressed using a quality factor from 1 to 100 with default being 55. When sending, or receiving, .jpg files, one should seek for quality factor of 55 and above to retain image quality at an acceptable level.
The basic uuencoding scheme breaks groups of three 8-bit characters into four 6-bit patterns and then adds ASCII code 32 (a space) to each 6-bit character which in turn maps it on to the character which is finally transmitted. Sometimes spaces are transmitted as grave-accent (' ASCII 96). The xxencoding is newer and limits itself to 0-9, A-Z, a-z and +- only. In case a compressed file is uuencoded, uudecode may have to be followed by an unzip step.
File sizes up to 100{300K are not uncommon for .gif files. Often UseNet files are delimited to 64k. A typical 640*480 VGA image may require transmission in multiple parts. Typical .gif file in Unix environment begins as follows:
begin 640 image.gif
640 represents the access rights of file.
Steps for getting a .gif or .jpg files may be as follows:
1. Step 1: Get all the parts of the image file as part files.
2. Step 2: Strip mail headers for each part-file.
3. Step 3: Concatenate all the parts to make one .uue file.
4. Step 4: uudecode to get a .gif/.jpg or .zip file.
5. Step 5: If it is a .zip file unzip it.
6. Step 6: If it is a .jpg file either use jpg image viewer like cview or, alternatively, use jpg2gif utility to get .gif file.
7. Step 7: View image from .gif file.
On the internet several conversion utilities are available and can be downloaded.
Performance Analysis and Profiling
One of the major needs in program development environments is to analyse and improve the performance of programs. For our examples here we assume c programs.
One may use some obviously efficient steps to improve efficiency of code. In his book, The Art Of Computer System Performance Analysis, Raj Jain advocates the following:
- Optimize the common case. In other words, if the program has to choose amongst several operational paths, then that path which is taken most often must be made very efficient. Statements in this path must be chosen carefully and must be screened to be optimal.
- In case we need to test some conditions and choose amongst many alternative paths by using a sequence of if statements, then we should arrange these if statements such that the condition most likely to succeed is tested first, i.e. optimize the test sequence to hit the most likely path quickly.
- Within an if statement if there are a set of conditions that are ANDED, then choose the first condition which is most likely to fail. This provides the quickest exit strategy.
- If the data to be checked is in the form of arrays or tables, then put these in the order such that the most likely ones to be accessed are up front, i.e. these get checked first.
- Avoid file input and output as much as possible. Also, batch as much input, or output, as possible. For instance, suppose we need to process each line of data. In such a case, get the file first in memory to process it line-by-line rather than reading the line-by-line data from disk for each step of processing.
- In the loops make sure to pull out as much data as possible. In particular, values that do not change within the loop computations need not be within the loop.
Steps To Analyze Performance Of c Programs: The following steps will walk us through the basic steps:
1. Compile with p option, the profiler option cc -p a.c
(Additionally, use -o option for linked routines.)
2. Now run the program a.out. (This step results in a mon.out file in the directory)
3. Next see the profile by using prof command as follows: prof a.out(For more details the reader is advised to see the options in man pages for prof command.)
The profiler gives an estimate of the time spent in each of the functions. Clearly, the functions that take a large percentage of time and are often used are the candidates for optimization.
A sample program profile: First let us study the following program in c:
#include <stdio.h>
#include <ctype.h>
int a1;
int a2;
add() /* adds two integers */
{
int x; int i;
for (i=1; i <=100000; i++)
x = a1 + a2; return x;
}
main()
{
int k; a1 = 5;
a2 = 2;
for (k=1; k <=1000000; k++);;
printf("The addition gives %d \n", add());
}
Now let us see the way it has been profiled.
bhatt@SE-0 [P] >>cc -p a.c bhatt@SE-0 [P] >>a.out The addition gives 7 bhatt@SE-0 [P] >>ls ReadMe a.c a.out mon.out
bhatt@SE-0 [P] >>prof a.out
bhatt@SE-0 [P] >>
The table above lists the percentage time spent in a certain function, time in seconds, and the number of calls made, average milliseconds on calls and the name of the function activated.
Another profiler is a gprof program. It additionally tries to find the number of iterated cycles in the program flow graph for function calls.
Text Processing (Improving Performance): Most often computer programs at tempt text processing. One of the common strategies is the use a loop in the following way:
1. Find the strlen (the length of the string).
2. Use a loop and do character-by-character scan to process data.
What most users do not realize is that the strlen itself determines the string length by traversing the string and comparing each of the characters with null.
Clearly, we can check in the loop if the character in the string array is null and process it if it is not. This can save a lot of processing time in a text processing program. Sometimes we are required to copy strings and use strcpy to do the task. If the architecture supports memory block copy, i.e. an instruction like memcpy then this is a preferred option as it is a block transfer instruction whereas strcpy copies byte-by-byte and is therefore very slow.
Comments
Post a Comment